Last active
July 19, 2016 14:28
-
-
Save kurozumi/33ba3b762106a0d437c88c1fed25c46d to your computer and use it in GitHub Desktop.
【Python】Pandasを使ってJリーグのクラブチーム(ファジアーノ岡山)の2016年シーズンの試合結果を取得する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"#pip install pandas lxml html5lib BeautifulSoup4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import urllib.parse\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"base_url = \"http://data.jleague.jp/SFMS01/search?\"\n", | |
" \n", | |
"url = base_url + urllib.parse.urlencode({\n", | |
" \"competition_years\": 2016,\n", | |
" \"team_ids\": 42,\n", | |
" \"home_away_select\": 1})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"databases = pd.io.html.read_html(url)\n", | |
"database = databases[0]\n", | |
"\n", | |
"# シーズン途中なので開催前の試合のnull値を削除\n", | |
"database = database.dropna()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>年度</th>\n", | |
" <th>大会</th>\n", | |
" <th>節</th>\n", | |
" <th>試合日</th>\n", | |
" <th>K/O時刻</th>\n", | |
" <th>ホーム</th>\n", | |
" <th>スコア</th>\n", | |
" <th>アウェイ</th>\n", | |
" <th>スタジアム</th>\n", | |
" <th>入場者数</th>\n", | |
" <th>TV放送</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第2節第1日</td>\n", | |
" <td>03/06(日)</td>\n", | |
" <td>14:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-1</td>\n", | |
" <td>千葉</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>9288.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第3節第2日</td>\n", | |
" <td>03/13(日)</td>\n", | |
" <td>13:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-2</td>\n", | |
" <td>京都</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>9098.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス/テレビせとうち</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第5節第1日</td>\n", | |
" <td>03/26(土)</td>\n", | |
" <td>13:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-0</td>\n", | |
" <td>北九州</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>7050.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第6節第1日</td>\n", | |
" <td>04/03(日)</td>\n", | |
" <td>13:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>1-1</td>\n", | |
" <td>東京V</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>7184.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第9節第1日</td>\n", | |
" <td>04/23(土)</td>\n", | |
" <td>19:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>0-1</td>\n", | |
" <td>山形</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>8256.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第10節第1日</td>\n", | |
" <td>04/29(金・祝)</td>\n", | |
" <td>14:04</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-2</td>\n", | |
" <td>町田</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>9170.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス/山陽放送</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第13節第1日</td>\n", | |
" <td>05/15(日)</td>\n", | |
" <td>14:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>0-1</td>\n", | |
" <td>岐阜</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>9464.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第14節第1日</td>\n", | |
" <td>05/22(日)</td>\n", | |
" <td>14:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-1</td>\n", | |
" <td>愛媛</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>8486.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第16節第1日</td>\n", | |
" <td>06/04(土)</td>\n", | |
" <td>13:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-1</td>\n", | |
" <td>熊本</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>7308.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス/岡山放送</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第18節第1日</td>\n", | |
" <td>06/12(日)</td>\n", | |
" <td>19:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-1</td>\n", | |
" <td>松本</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>8193.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第21節第1日</td>\n", | |
" <td>07/03(日)</td>\n", | |
" <td>18:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>2-2</td>\n", | |
" <td>清水</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>11090.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>2016</td>\n", | |
" <td>J2</td>\n", | |
" <td>第23節第1日</td>\n", | |
" <td>07/16(土)</td>\n", | |
" <td>19:03</td>\n", | |
" <td>岡山</td>\n", | |
" <td>0-0</td>\n", | |
" <td>札幌</td>\n", | |
" <td>Cスタ</td>\n", | |
" <td>13304.0</td>\n", | |
" <td>スカパー!/スカパー!プレミアムサービス/テレビせとうち</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" 年度 大会 節 試合日 K/O時刻 ホーム スコア アウェイ スタジアム 入場者数 \\\n", | |
"0 2016 J2 第2節第1日 03/06(日) 14:03 岡山 2-1 千葉 Cスタ 9288.0 \n", | |
"1 2016 J2 第3節第2日 03/13(日) 13:03 岡山 2-2 京都 Cスタ 9098.0 \n", | |
"2 2016 J2 第5節第1日 03/26(土) 13:03 岡山 2-0 北九州 Cスタ 7050.0 \n", | |
"3 2016 J2 第6節第1日 04/03(日) 13:03 岡山 1-1 東京V Cスタ 7184.0 \n", | |
"4 2016 J2 第9節第1日 04/23(土) 19:03 岡山 0-1 山形 Cスタ 8256.0 \n", | |
"5 2016 J2 第10節第1日 04/29(金・祝) 14:04 岡山 2-2 町田 Cスタ 9170.0 \n", | |
"6 2016 J2 第13節第1日 05/15(日) 14:03 岡山 0-1 岐阜 Cスタ 9464.0 \n", | |
"7 2016 J2 第14節第1日 05/22(日) 14:03 岡山 2-1 愛媛 Cスタ 8486.0 \n", | |
"8 2016 J2 第16節第1日 06/04(土) 13:03 岡山 2-1 熊本 Cスタ 7308.0 \n", | |
"9 2016 J2 第18節第1日 06/12(日) 19:03 岡山 2-1 松本 Cスタ 8193.0 \n", | |
"10 2016 J2 第21節第1日 07/03(日) 18:03 岡山 2-2 清水 Cスタ 11090.0 \n", | |
"11 2016 J2 第23節第1日 07/16(土) 19:03 岡山 0-0 札幌 Cスタ 13304.0 \n", | |
"\n", | |
" TV放送 \n", | |
"0 スカパー!/スカパー!プレミアムサービス \n", | |
"1 スカパー!/スカパー!プレミアムサービス/テレビせとうち \n", | |
"2 スカパー!/スカパー!プレミアムサービス \n", | |
"3 スカパー!/スカパー!プレミアムサービス \n", | |
"4 スカパー!/スカパー!プレミアムサービス \n", | |
"5 スカパー!/スカパー!プレミアムサービス/山陽放送 \n", | |
"6 スカパー!/スカパー!プレミアムサービス \n", | |
"7 スカパー!/スカパー!プレミアムサービス \n", | |
"8 スカパー!/スカパー!プレミアムサービス/岡山放送 \n", | |
"9 スカパー!/スカパー!プレミアムサービス \n", | |
"10 スカパー!/スカパー!プレミアムサービス \n", | |
"11 スカパー!/スカパー!プレミアムサービス/テレビせとうち " | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"database" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [py35]", | |
"language": "python", | |
"name": "Python [py35]" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment