├── .gitignore ├── Presentation.pdf ├── 2.DelhiWeatherAnalysis ├── MonthWiseWeatherTrends.png ├── MonthlyQuantitativeAnalysis.png └── DataAnalysis.ipynb ├── README.md ├── 4.IPLAnalysis ├── data │ └── teams.csv └── DataAnalysis.ipynb ├── 3.FIFAWC18Analysis ├── data │ ├── teams.csv │ ├── matches.csv │ ├── goals.csv │ └── players.csv ├── DataCollection.ipynb └── DataAnalysis.ipynb └── 1.PandasBasics ├── Exercise.ipynb └── data └── bikes.csv /.gitignore: -------------------------------------------------------------------------------- 1 | \.ipynb_checkpoints 2 | -------------------------------------------------------------------------------- /Presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilkumarsingh/PracticalPandas/HEAD/Presentation.pdf -------------------------------------------------------------------------------- /2.DelhiWeatherAnalysis/MonthWiseWeatherTrends.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilkumarsingh/PracticalPandas/HEAD/2.DelhiWeatherAnalysis/MonthWiseWeatherTrends.png -------------------------------------------------------------------------------- /2.DelhiWeatherAnalysis/MonthlyQuantitativeAnalysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhilkumarsingh/PracticalPandas/HEAD/2.DelhiWeatherAnalysis/MonthlyQuantitativeAnalysis.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PracticalPandas 2 | A practical way to learn Pandas. 3 | 4 | This repository contains the presentation and notebook material for "Practical Pandas" workshop at PyData Delhi, 2018. 5 | -------------------------------------------------------------------------------- /4.IPLAnalysis/data/teams.csv: -------------------------------------------------------------------------------- 1 | name 2 | Mumbai Indians 3 | Kings XI Punjab 4 | Chennai Super Kings 5 | Royal Challengers Bangalore 6 | Kolkata Knight Riders 7 | Delhi Daredevils 8 | Rajasthan Royals 9 | Sunrisers Hyderabad 10 | Deccan Chargers 11 | Pune Warriors 12 | Gujarat Lions 13 | Rising Pune Supergiant 14 | Rising Pune Supergiants 15 | Kochi Tuskers Kerala 16 | -------------------------------------------------------------------------------- /3.FIFAWC18Analysis/data/teams.csv: -------------------------------------------------------------------------------- 1 | IdTeam,TeamName,CoachName,CoachCountry 2 | 43929,Peru,GARECA Ricardo,Argentina 3 | 43872,Morocco,RENARD Herve,France 4 | 43855,Egypt,CUPER Hector,Argentina 5 | 43817,IR Iran,QUEIROZ Carlos,Portugal 6 | 43911,Mexico,OSORIO Juan Carlos,Colombia 7 | 43835,Saudi Arabia,PIZZI Juan Antonio,Spain 8 | 43970,Sweden,ANDERSSON Janne,Sweden 9 | 43946,France,DESCHAMPS Didier,France 10 | 43879,Senegal,CISSE Aliou,Senegal 11 | 43938,Croatia,DALIC Zlatko,Croatia 12 | 43962,Poland,NAWALKA Adam,Poland 13 | 43924,Brazil,TITE,Brazil 14 | 43819,Japan,NISHINO Akira,Japan 15 | 43926,Colombia,PEKERMAN Jose,Argentina 16 | 43969,Spain,HIERRO Fernando,Spain 17 | 43971,Switzerland,PETKOVIC Vladimir,Switzerland 18 | 43941,Denmark,HAREIDE Age,Norway 19 | 43914,Panama,GOMEZ Hernan,Colombia 20 | 43888,Tunisia,MAALOUL Nabil,Tunisia 21 | 43930,Uruguay,TABAREZ Oscar,Uruguay 22 | 43963,Portugal,SANTOS Fernando,Portugal 23 | 43976,Australia,VAN MARWIJK Bert,Netherlands 24 | 43948,Germany,LÖW Joachim,Germany 25 | 43901,Costa Rica,RAMIREZ Oscar,Costa Rica 26 | 1902465,Serbia,KRSTAJIC Mladen,Serbia 27 | 43951,Iceland,HALLGRIMSSON Heimir,Iceland 28 | 43942,England,SOUTHGATE Gareth,England 29 | 43876,Nigeria,ROHR Gernot,Germany 30 | 43922,Argentina,SAMPAOLI Jorge,Argentina 31 | 43822,Korea Republic,SHIN Taeyong,Korea Republic 32 | 43965,Russia,CHERCHESOV Stanislav,Russia 33 | 43935,Belgium,MARTINEZ Roberto,Spain 34 | -------------------------------------------------------------------------------- /2.DelhiWeatherAnalysis/DataAnalysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![](https://derrickmartins.files.wordpress.com/2015/11/time-series-analysis.png)\n", 8 | "\n", 9 | "# Time series analysis using Pandas\n", 10 | "\n", 11 | "https://www.kaggle.com/mahirkukreja/delhi-weather-data" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import calendar\n", 21 | "import pandas as pd\n", 22 | "import matplotlib.pyplot as plt\n", 23 | "from random import random\n", 24 | "%matplotlib inline" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "df = pd.read_csv(\"data/dataset.csv\", parse_dates=['datetime_utc'], index_col='datetime_utc')" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "### Clean data\n", 41 | "![](https://y1vwcp5chj-flywheel.netdna-ssl.com/wp-content/uploads/2016/10/blog-meme.jpg)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "df.columns" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": { 57 | "scrolled": true 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "df.describe()" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "# rename columns\n", 71 | "new_cols = [x.replace(' _','') for x in df.columns]\n", 72 | "df.columns = new_cols" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "# remove field with all NaNs\n", 82 | "df = df.drop('precipm', axis=1)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "# take care of wrong readings\n", 92 | "df['pressurem'] = df['pressurem'].apply(lambda x: df['pressurem'].mean() if not 800120 else x)\n", 94 | "df['vism'] = df['vism'].apply(lambda x: df['vism'].mean() if x>10 else x)\n", 95 | "df['wspdm'] = df['wspdm'].apply(lambda x: df['wspdm'].mean() if x>300 else x)\n", 96 | "df['tempm'] = df['tempm'].apply(lambda x: df['tempm'].mean() if x>50 else x)" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "# extra columns for time analysis\n", 106 | "df['hour'] = df.index.hour\n", 107 | "df['day'] = df.index.day\n", 108 | "df['month'] = df.index.month\n", 109 | "df['year'] = df.index.year" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "### Quantitative plots over years/months/hours" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "# list of numeric columns\n", 126 | "cols = ['dewptm', 'fog', 'hail', 'heatindexm', 'hum', 'pressurem', 'rain', 'snow', 'tempm', 'thunder', 'tornado', \n", 127 | " 'vism', 'wdird', 'wgustm', 'windchillm', 'wspdm']" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": null, 133 | "metadata": {}, 134 | "outputs": [], 135 | "source": [ 136 | "# quantitative plots\n", 137 | "fig, axes = plt.subplots(4, 4, figsize=(16, 16))\n", 138 | "\n", 139 | "for idx, col in enumerate(cols):\n", 140 | " ax = axes[idx // 4, idx % 4]\n", 141 | " ax.plot(df.groupby('month')[col].mean())\n", 142 | " ax.set_title(col)\n", 143 | "\n", 144 | "fig.subplots_adjust(wspace=0.3, hspace=0.3)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "### Weather conditions trends per month\n", 152 | "![](https://i.pinimg.com/originals/19/a5/66/19a566d915debc41d7e303666b7ea10f.jpg)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": null, 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "month_wise_conds = df.groupby(['month', 'conds'])['month'].count()" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [ 170 | "month_wise_conds_df = month_wise_conds.unstack(level=1)" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": null, 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "month_wise_conds_df" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "# color dict of weather conditions\n", 189 | "colordic = {}\n", 190 | "for idx, cond in enumerate(month_wise_conds_df.columns.values):\n", 191 | " colordic[cond] = (random(), random(), random(), 1)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "metadata": {}, 198 | "outputs": [], 199 | "source": [ 200 | "fig, axes = plt.subplots(4, 3, figsize=(15, 15))\n", 201 | "\n", 202 | "for i, (idx, row) in enumerate(month_wise_conds_df.iterrows()):\n", 203 | " ax = axes[i // 3, i % 3]\n", 204 | " # remove conditions with small percentage\n", 205 | " row = row[row.gt(row.sum() * .03)]\n", 206 | " # set color list for pie chart\n", 207 | " colors = [colordic[val] for val in row.index]\n", 208 | " ax.pie(row, labels=row.index, colors=colors)\n", 209 | " ax.set_title(calendar.month_name[idx])\n", 210 | "\n", 211 | "fig.subplots_adjust(wspace=1.0, hspace=0.2)" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "metadata": { 218 | "scrolled": false 219 | }, 220 | "outputs": [], 221 | "source": [ 222 | "# what has been the weather like on this day for past 20 years?\n", 223 | "df.query(\"month == 8 and day == 1 and hour == 15\")['conds'].value_counts().plot.pie(figsize=(8, 8), autopct='%1.0f%%')" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": null, 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "# month wise data over the years\n", 233 | "pv = pd.pivot_table(df.query(\"year%5 == 0\"), index=['month'], columns=['year'],\n", 234 | " values='vism', aggfunc='mean')" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": null, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "pv.plot()" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "metadata": {}, 249 | "source": [ 250 | "## Depressing, but true...\n", 251 | "![](https://s3.scoopwhoop.com/anj/sw/a1153a33-b90b-4fc2-a569-745a78b950e8.jpg)" 252 | ] 253 | } 254 | ], 255 | "metadata": { 256 | "kernelspec": { 257 | "display_name": "Python 3", 258 | "language": "python", 259 | "name": "python3" 260 | }, 261 | "language_info": { 262 | "codemirror_mode": { 263 | "name": "ipython", 264 | "version": 3 265 | }, 266 | "file_extension": ".py", 267 | "mimetype": "text/x-python", 268 | "name": "python", 269 | "nbconvert_exporter": "python", 270 | "pygments_lexer": "ipython3", 271 | "version": "3.6.5" 272 | } 273 | }, 274 | "nbformat": 4, 275 | "nbformat_minor": 2 276 | } 277 | -------------------------------------------------------------------------------- /3.FIFAWC18Analysis/data/matches.csv: -------------------------------------------------------------------------------- 1 | IdMatch,HomeTeamName,AwayTeamName,Attendance,MatchDay,Date,Stage,HomeTeamTactics,AwayTeamTactics,HomeTeamScore,AwayTeamScore,HomeTeamPenaltyScore,AwayTeamPenaltyScore,IsHomeMatch,MatchStatus,ResultType,StadiumName,Temperature,Humidity,WindSpeed,WeatherType,BallPossessionHome,BallPossessionAway,Winner 2 | 300331503,Russia,Saudi Arabia,78011,1,2018-06-14T15:00:00Z,First stage,4-2-3-1,4-5-1,5,0,0,0,,0,1,Luzhniki Stadium,17,43,6,Partly Cloudy,40.0,60.0,Russia 3 | 300353632,Egypt,Uruguay,27015,2,2018-06-15T12:00:00Z,First stage,4-2-3-1,4-4-2,0,1,0,0,,0,1,Ekaterinburg Arena,14,42,29,Partly Cloudy,43.0,57.0,Uruguay 4 | 300331526,Morocco,IR Iran,62548,2,2018-06-15T15:00:00Z,First stage,3-4-3,3-4-3,0,1,0,0,,0,1,Saint Petersburg Stadium,25,37,13,Partly Cloudy,64.0,36.0,IR Iran 5 | 300331524,Portugal,Spain,43866,2,2018-06-15T18:00:00Z,First stage,4-2-3-1,4-2-3-1,3,3,0,0,,0,1,Fisht Stadium,24,74,10,Partly Cloudy Night,39.0,61.0, 6 | 300331533,France,Australia,41279,3,2018-06-16T10:00:00Z,First stage,4-3-3,4-2-3-1,2,1,0,0,,0,1,Kazan Arena,19,32,19,Sunny,51.0,49.0,France 7 | 300331515,Argentina,Iceland,44190,3,2018-06-16T13:00:00Z,First stage,4-2-3-1,4-5-1,1,1,0,0,,0,1,Spartak Stadium,22,33,11,Sunny,72.0,28.0, 8 | 300331528,Peru,Denmark,40502,3,2018-06-16T16:00:00Z,First stage,4-2-3-1,4-3-3,0,1,0,0,,0,1,Mordovia Arena,18,48,12,Partly Cloudy,52.0,48.0,Denmark 9 | 300331523,Croatia,Nigeria,31136,3,2018-06-16T19:00:00Z,First stage,4-2-3-1,4-2-3-1,2,0,0,0,,0,1,Kaliningrad Stadium,20,64,7,Partly Cloudy,54.0,46.0,Croatia 10 | 300331529,Costa Rica,Serbia,41432,4,2018-06-17T12:00:00Z,First stage,5-4-1,4-2-3-1,0,1,0,0,,0,1,Samara Arena,22,32,18,Sunny,50.0,50.0,Serbia 11 | 300331502,Germany,Mexico,78011,4,2018-06-17T15:00:00Z,First stage,4-2-3-1,4-2-3-1,0,1,0,0,,0,1,Luzhniki Stadium,23,42,11,Sunny,60.0,40.0,Mexico 12 | 300331525,Brazil,Switzerland,43109,4,2018-06-17T18:00:00Z,First stage,4-2-3-1,4-2-3-1,1,1,0,0,,0,1,Rostov Arena,25,27,16,Partly Cloudy Night,52.0,48.0, 13 | 300331499,Sweden,Korea Republic,42300,5,2018-06-18T12:00:00Z,First stage,4-4-2,4-3-3,1,0,0,0,,0,1,Nizhny Novgorod Stadium,25,36,9,Partly Cloudy,52.0,48.0,Sweden 14 | 300331539,Belgium,Panama,43257,5,2018-06-18T15:00:00Z,First stage,3-4-2-1,4-5-1,3,0,0,0,,0,1,Fisht Stadium,24,71,12,Partly Cloudy,61.0,39.0,Belgium 15 | 300331554,Tunisia,England,41064,5,2018-06-18T18:00:00Z,First stage,4-3-3,3-5-2,1,2,0,0,,0,1,Volgograd Arena,24,17,7,Clear Night,41.0,59.0,England 16 | 300331550,Colombia,Japan,40842,6,2018-06-19T12:00:00Z,First stage,4-2-3-1,4-2-3-1,1,2,0,0,,0,1,Mordovia Arena,27,38,12,Sunny,41.0,59.0,Japan 17 | 300331545,Poland,Senegal,44190,6,2018-06-19T15:00:00Z,First stage,4-2-3-1,4-4-2,1,2,0,0,,0,1,Spartak Stadium,27,40,19,Cloudy,57.0,43.0,Senegal 18 | 300331495,Russia,Egypt,64468,6,2018-06-19T18:00:00Z,First stage,4-2-3-1,4-2-3-1,3,1,0,0,,0,1,Saint Petersburg Stadium,15,83,14,Cloudy,47.0,53.0,Russia 19 | 300331511,Portugal,Morocco,78011,7,2018-06-20T12:00:00Z,First stage,4-4-2,4-2-3-1,1,0,0,0,,0,1,Luzhniki Stadium,20,33,24,Partly Cloudy,47.0,53.0,Portugal 20 | 300331530,Uruguay,Saudi Arabia,42678,7,2018-06-20T15:00:00Z,First stage,4-4-2,4-5-1,1,0,0,0,,0,1,Rostov Arena,32,26,10,Sunny,47.0,53.0,Uruguay 21 | 300331496,IR Iran,Spain,42718,7,2018-06-20T18:00:00Z,First stage,4-2-3-1,4-2-3-1,0,1,0,0,,0,1,Kazan Arena,18,48,26,Clear Night,30.0,70.0,Spain 22 | 300331518,Denmark,Australia,40727,8,2018-06-21T12:00:00Z,First stage,4-3-3,4-2-3-1,1,1,0,0,,0,1,Samara Arena,24,32,25,Sunny,49.0,51.0, 23 | 300331527,France,Peru,32789,8,2018-06-21T15:00:00Z,First stage,4-2-3-1,4-2-3-1,1,0,0,0,,0,1,Ekaterinburg Arena,12,79,21,Cloudy,44.0,56.0,France 24 | 300331513,Argentina,Croatia,43319,8,2018-06-21T18:00:00Z,First stage,3-4-3,4-2-3-1,0,3,0,0,,0,1,Nizhny Novgorod Stadium,17,49,15,Clear Night,58.0,42.0,Croatia 25 | 300331540,Brazil,Costa Rica,64468,9,2018-06-22T12:00:00Z,First stage,4-2-3-1,5-4-1,2,0,0,0,,0,1,Saint Petersburg Stadium,19,70,19,Cloudy,66.0,34.0,Brazil 26 | 300331497,Nigeria,Iceland,40904,9,2018-06-22T15:00:00Z,First stage,3-5-2,4-4-2,2,0,0,0,,0,1,Volgograd Arena,32,19,2,Sunny,58.0,42.0,Nigeria 27 | 300340183,Serbia,Switzerland,33167,9,2018-06-22T18:00:00Z,First stage,4-2-3-1,4-2-3-1,1,2,0,0,,0,1,Kaliningrad Stadium,15,55,11,Sunny,42.0,58.0,Switzerland 28 | 300331547,Belgium,Tunisia,44190,10,2018-06-23T12:00:00Z,First stage,3-4-3,4-3-3,5,2,0,0,,0,1,Spartak Stadium,28,64,12,Partly Cloudy,52.0,48.0,Belgium 29 | 300331549,Korea Republic,Mexico,43472,10,2018-06-23T15:00:00Z,First stage,4-4-2,4-3-3,1,2,0,0,,0,1,Rostov Arena,33,28,11,Partly Cloudy,41.0,59.0,Mexico 30 | 300331501,Germany,Sweden,44287,10,2018-06-23T18:00:00Z,First stage,4-2-3-1,4-4-2,2,1,0,0,,0,1,Fisht Stadium,22,80,11,Partly Cloudy Night,71.0,29.0,Germany 31 | 300331546,England,Panama,43319,11,2018-06-24T12:00:00Z,First stage,3-5-2,4-5-1,6,1,0,0,,0,1,Nizhny Novgorod Stadium,30,33,15,Partly Cloudy,58.0,42.0,England 32 | 300331505,Japan,Senegal,32572,11,2018-06-24T15:00:00Z,First stage,4-2-3-1,4-3-3,2,2,0,0,,0,1,Ekaterinburg Arena,25,38,26,Sunny,54.0,46.0, 33 | 300331508,Poland,Colombia,42873,11,2018-06-24T18:00:00Z,First stage,3-4-3,4-2-3-1,0,3,0,0,,0,1,Kazan Arena,26,58,8,Clear Night,45.0,55.0,Colombia 34 | 300331516,Uruguay,Russia,41970,12,2018-06-25T14:00:00Z,First stage,3-5-2,4-2-3-1,3,0,0,0,,0,1,Samara Arena,32,34,6,Sunny,56.0,44.0,Uruguay 35 | 300331509,Saudi Arabia,Egypt,36823,12,2018-06-25T14:00:00Z,First stage,4-5-1,4-2-3-1,2,1,0,0,,0,1,Volgograd Arena,35,24,10,Partly Cloudy,61.0,39.0,Saudi Arabia 36 | 300340184,Spain,Morocco,33973,12,2018-06-25T18:00:00Z,First stage,4-2-3-1,4-2-3-1,2,2,0,0,,0,1,Kaliningrad Stadium,15,70,13,Partly Cloudy Night,68.0,32.0, 37 | 300331500,IR Iran,Portugal,41685,12,2018-06-25T18:00:00Z,First stage,4-5-1,4-4-2,1,1,0,0,,0,1,Mordovia Arena,23,70,9,Partly Cloudy Night,32.0,68.0, 38 | 300331506,Australia,Peru,44073,13,2018-06-26T14:00:00Z,First stage,4-2-3-1,4-2-3-1,0,2,0,0,,0,1,Fisht Stadium,30,70,10,Partly Cloudy,53.0,47.0,Peru 39 | 300331512,Denmark,France,78011,13,2018-06-26T14:00:00Z,First stage,4-3-3,4-2-3-1,0,0,0,0,,0,1,Luzhniki Stadium,24,34,11,Partly Cloudy,38.0,62.0, 40 | 300331519,Nigeria,Argentina,64468,13,2018-06-26T18:00:00Z,First stage,3-5-2,4-4-2,1,2,0,0,,0,1,Saint Petersburg Stadium,22,45,18,Sunny,34.0,66.0,Argentina 41 | 300331510,Iceland,Croatia,43472,13,2018-06-26T18:00:00Z,First stage,4-2-3-1,4-2-3-1,1,2,0,0,,0,1,Rostov Arena,30,38,21,Clear Night,41.0,59.0,Croatia 42 | 300331532,Korea Republic,Germany,41835,14,2018-06-27T14:00:00Z,First stage,4-4-2,4-2-3-1,2,0,0,0,,0,1,Kazan Arena,28,40,18,Sunny,30.0,70.0,Korea Republic 43 | 300331548,Mexico,Sweden,33061,14,2018-06-27T14:00:00Z,First stage,4-2-3-1,4-4-2,0,3,0,0,,0,1,Ekaterinburg Arena,27,42,18,Sunny,65.0,35.0,Sweden 44 | 300331521,Serbia,Brazil,44190,14,2018-06-27T18:00:00Z,First stage,4-2-3-1,4-2-3-1,0,2,0,0,,0,1,Spartak Stadium,24,42,12,Partly Cloudy,44.0,56.0,Brazil 45 | 300331534,Switzerland,Costa Rica,43319,14,2018-06-27T18:00:00Z,First stage,4-2-3-1,5-4-1,2,2,0,0,,0,1,Nizhny Novgorod Stadium,20,43,13,Clear Night,60.0,40.0, 46 | 300331507,Japan,Poland,42189,15,2018-06-28T14:00:00Z,First stage,4-2-3-1,3-4-3,0,1,0,0,,0,1,Volgograd Arena,36,24,13,Sunny,54.0,46.0,Poland 47 | 300331553,Senegal,Colombia,41970,15,2018-06-28T14:00:00Z,First stage,4-4-2,4-2-3-1,0,1,0,0,,0,1,Samara Arena,27,34,21,Sunny,43.0,57.0,Colombia 48 | 300331520,Panama,Tunisia,37168,15,2018-06-28T18:00:00Z,First stage,4-5-1,4-3-3,1,2,0,0,,0,1,Mordovia Arena,20,60,7,Clear Night,36.0,64.0,Tunisia 49 | 300340182,England,Belgium,33973,15,2018-06-28T18:00:00Z,First stage,3-5-2,3-4-3,0,1,0,0,,0,1,Kaliningrad Stadium,21,61,11,Sunny,48.0,52.0,Belgium 50 | 300331537,France,Argentina,42873,16,2018-06-30T14:00:00Z,Round of 16,4-2-3-1,4-3-3,4,3,0,0,,0,1,Kazan Arena,28,33,12,Sunny,41.0,59.0,France 51 | 300331544,Uruguay,Portugal,44287,16,2018-06-30T18:00:00Z,Round of 16,4-4-2,4-4-2,2,1,0,0,,0,1,Fisht Stadium,27,74,11,Clear Night,39.0,61.0,Uruguay 52 | 300331517,Spain,Russia,78011,17,2018-07-01T14:00:00Z,Round of 16,4-2-3-1,5-3-2,1,1,3,4,,0,2,Luzhniki Stadium,24,63,13,Partly Cloudy,75.0,25.0,Russia 53 | 300331498,Croatia,Denmark,40851,17,2018-07-01T18:00:00Z,Round of 16,4-2-3-1,4-3-3,1,1,3,2,,0,2,Nizhny Novgorod Stadium,25,48,15,Partly Cloudy Night,54.0,46.0,Croatia 54 | 300331535,Brazil,Mexico,41970,18,2018-07-02T14:00:00Z,Round of 16,4-2-3-1,4-3-3,2,0,0,0,,0,1,Samara Arena,33,28,14,Sunny,47.0,53.0,Brazil 55 | 300331551,Belgium,Japan,41466,18,2018-07-02T18:00:00Z,Round of 16,3-4-3,4-2-3-1,3,2,0,0,,0,1,Rostov Arena,25,36,9,Clear Night,56.0,44.0,Belgium 56 | 300331514,Sweden,Switzerland,64042,19,2018-07-03T14:00:00Z,Round of 16,4-4-2,4-2-3-1,1,0,0,0,,0,1,Saint Petersburg Stadium,18,60,10,Partly Cloudy,37.0,63.0,Sweden 57 | 300331542,Colombia,England,44190,19,2018-07-03T18:00:00Z,Round of 16,4-3-2-1,3-5-2,1,1,3,4,,0,2,Spartak Stadium,18,61,7,Cloudy,49.0,51.0,England 58 | 300331543,Uruguay,France,43319,20,2018-07-06T14:00:00Z,Quarter-finals,4-4-2,4-2-3-1,0,2,0,0,,0,1,Nizhny Novgorod Stadium,22,53,13,Partly Cloudy,42.0,58.0,France 59 | 300331538,Brazil,Belgium,42873,20,2018-07-06T18:00:00Z,Quarter-finals,4-2-3-1,3-4-3,1,2,0,0,,0,1,Kazan Arena,20,60,9,Partly Cloudy Night,57.0,43.0,Belgium 60 | 300331541,Sweden,England,39991,21,2018-07-07T14:00:00Z,Quarter-finals,4-4-2,3-5-2,0,2,0,0,,0,1,Samara Arena,26,39,7,Partly Cloudy,43.0,57.0,England 61 | 300331504,Russia,Croatia,44287,21,2018-07-07T18:00:00Z,Quarter-finals,4-2-3-1,4-2-3-1,2,2,3,4,,0,2,Fisht Stadium,24,70,12,Clear Night,38.0,62.0,Croatia 62 | 300331531,France,Belgium,64286,22,2018-07-10T18:00:00Z,Semi-finals,4-2-3-1,3-5-2,1,0,0,0,,0,1,Saint Petersburg Stadium,18,75,11,Cloudy,40.0,60.0,France 63 | 300331522,Croatia,England,78011,23,2018-07-11T18:00:00Z,Semi-finals,4-2-3-1,3-5-2,2,1,0,0,,0,3,Luzhniki Stadium,21,64,6,Cloudy,54.0,46.0,Croatia 64 | 300331536,Belgium,England,64406,24,2018-07-14T14:00:00Z,Play-off for third place,3-4-3,3-5-2,2,0,0,0,,0,1,Saint Petersburg Stadium,26,45,10,Partly Cloudy,43.0,57.0,Belgium 65 | 300331552,France,Croatia,78011,25,2018-07-15T15:00:00Z,Final,4-2-3-1,4-2-3-1,4,2,0,0,,0,1,Luzhniki Stadium,27,51,3,Partly Cloudy,39.0,61.0,France 66 | -------------------------------------------------------------------------------- /4.IPLAnalysis/DataAnalysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![](https://i.imgur.com/62lgQpf.jpg)\n", 8 | "\n", 9 | "-----\n", 10 | "\n", 11 | "## About the dataset\n", 12 | "https://www.kaggle.com/nowke9/ipldata\n", 13 | "- `teams.csv`: list of IPL teams\n", 14 | "- `matches.csv`: IPL match data\n", 15 | "- `deliveries.csv`: Ball by ball data of IPL matches.\n", 16 | "\n", 17 | "## Questions we are gonna answer...\n", 18 | "\n", 19 | "- Which team has won/lost maximum number of matches while chasing?\n", 20 | "- Which toss decision is best for each ground?\n", 21 | "- Which player has won maximum number of MoM awards while chasing?\n", 22 | "\n", 23 | "- Which batsman has played maximum number of dot balls?\n", 24 | "- Which batsmen came to crease but never got a chance to face a ball?\n", 25 | "- Which bowler has hit for maximum number of 1s/2s/3s/4s/6s?\n", 26 | "- Which batsman got stumped out maximum number of times?\n", 27 | "- Which non-striker has been part of maximum number of runouts?\n", 28 | "\n", 29 | "\n", 30 | "Finally,\n", 31 | "\n", 32 | "**How to make a generalized IPL query engine?**" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "import pandas as pd" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "teams_df = pd.read_csv(\"data/teams.csv\")" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "matches_df = pd.read_csv(\"data/matches.csv\", index_col='id')" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "deliveries_df = pd.read_csv(\"data/deliveries.csv\")" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "## Which team has won/lost maximum number of matches while chasing?" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "def set_first_innings(match):\n", 85 | " if (match.team1 == match.toss_winner and match.toss_decision == \"bat\") \\\n", 86 | " or (match.team1 != match.toss_winner and match.toss_decision == \"field\"):\n", 87 | " return match.team1\n", 88 | " else:\n", 89 | " return match.team2\n", 90 | " \n", 91 | " \n", 92 | "def set_second_innings(match):\n", 93 | " if (match.team1 == match.toss_winner and match.toss_decision == \"field\") \\\n", 94 | " or (match.team1 != match.toss_winner and match.toss_decision == \"bat\"):\n", 95 | " return match.team1\n", 96 | " else:\n", 97 | " return match.team2" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "matches_df['inning1'] = matches_df.apply(set_first_innings, axis=1)\n", 107 | "matches_df['inning2'] = matches_df.apply(set_second_innings, axis=1)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "scrolled": true 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "# maximum number of matches won while chasing\n", 119 | "matches_df.query(\"winner == inning2\")['inning2'].value_counts()" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": { 126 | "scrolled": true 127 | }, 128 | "outputs": [], 129 | "source": [ 130 | "# maximum number of matches lost while chasing\n", 131 | "matches_df.query(\"winner != inning2\")['inning2'].value_counts()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "## Which toss decision is best for each ground?" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [ 147 | "%matplotlib inline" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": { 154 | "scrolled": false 155 | }, 156 | "outputs": [], 157 | "source": [ 158 | "matches_df.query(\"toss_winner == winner\").groupby('venue')['toss_decision'].value_counts().unstack(level=1).plot.bar(figsize=(15,5))" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": {}, 164 | "source": [ 165 | "## Which player has won maximum number of MoM awards while chasing?" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [ 174 | "matches_df.query(\"winner == inning2\")['player_of_match'].value_counts().sort_values(ascending=False).head()" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "## Which batsman has played maximum number of dot balls?" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "metadata": {}, 188 | "outputs": [], 189 | "source": [ 190 | "deliveries_df.query(\"batsman_runs == 0 and extra_runs == 0\")['batsman'].value_counts().head()" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": {}, 196 | "source": [ 197 | "## Which batsmen came to crease but never got a chance to face a ball?" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "a = deliveries_df['non_striker'].value_counts().index" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "b = deliveries_df['batsman'].value_counts().index" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "a.difference(b)" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "## Which batsman has hit for maximum number of 1s/2s/3s/4s/6s?" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": null, 237 | "metadata": { 238 | "scrolled": false 239 | }, 240 | "outputs": [], 241 | "source": [ 242 | "deliveries_df.query(\"batsman_runs == 6\")['batsman'].value_counts().head()" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "metadata": {}, 248 | "source": [ 249 | "## Which batsman got stumped out maximum number of times?" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "deliveries_df.query(\"dismissal_kind == 'stumped'\")['batsman'].value_counts().head()" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "## Which non-striker has been part of maximum number of runouts?" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": null, 271 | "metadata": { 272 | "scrolled": true 273 | }, 274 | "outputs": [], 275 | "source": [ 276 | "deliveries_df.query(\"dismissal_kind == 'run out'\")['non_striker'].value_counts().head()" 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "metadata": {}, 282 | "source": [ 283 | "\n", 284 | "---\n", 285 | "\n", 286 | "# A generalized query engine...\n", 287 | "\n", 288 | "[IPLQE](https://iplqe.herokuapp.com)\n", 289 | "\n", 290 | "**Actors are:**\n", 291 | "- Batsmen (batsman)\n", 292 | "- Bowlers (bowler)\n", 293 | "- Fielders (fielders)\n", 294 | "- Non strikers (non_striker)\n", 295 | "- Dismissed batsmen (player_out)\n", 296 | "- Batting teams (bat_team)\n", 297 | "- Bowling teams (bowl_team)\n", 298 | "\n", 299 | "**To calculate parameters:**\n", 300 | "- runs (total_runs)\n", 301 | "- runs by bat (batsman_runs)\n", 302 | "- extra runs (extra_runs)\n", 303 | "- wickets (player_out)\n", 304 | "- deliveries (ball)\n", 305 | "\n", 306 | "**Filters available:**\n", 307 | "- season\n", 308 | "- innings\n", 309 | "- bat_team\n", 310 | "- bowl_team\n", 311 | "- over\n", 312 | "- ball\n", 313 | "- batsman_runs\n", 314 | "- extra_runs\n", 315 | "- total_runs\n", 316 | "- extra_type\n", 317 | "- wicket_kind\n", 318 | "\n", 319 | "\n", 320 | "![](https://i.imgur.com/mernK4C.png)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": null, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "filters = \"inning == 2 and over == 20\"" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": null, 335 | "metadata": {}, 336 | "outputs": [], 337 | "source": [ 338 | "actor = \"batsman\"" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": null, 344 | "metadata": {}, 345 | "outputs": [], 346 | "source": [ 347 | "to_calculate = \"batsman_runs\"" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": null, 353 | "metadata": {}, 354 | "outputs": [], 355 | "source": [ 356 | "deliveries_df.query(filters).groupby(actor)[to_calculate].sum().sort_values(ascending=False).head(10)" 357 | ] 358 | } 359 | ], 360 | "metadata": { 361 | "kernelspec": { 362 | "display_name": "Python 3", 363 | "language": "python", 364 | "name": "python3" 365 | }, 366 | "language_info": { 367 | "codemirror_mode": { 368 | "name": "ipython", 369 | "version": 3 370 | }, 371 | "file_extension": ".py", 372 | "mimetype": "text/x-python", 373 | "name": "python", 374 | "nbconvert_exporter": "python", 375 | "pygments_lexer": "ipython3", 376 | "version": "3.6.5" 377 | } 378 | }, 379 | "nbformat": 4, 380 | "nbformat_minor": 2 381 | } 382 | -------------------------------------------------------------------------------- /1.PandasBasics/Exercise.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#
Introduction to Pandas
\n", 8 | "\n", 9 | "![](https://pandas.pydata.org/_static/pandas_logo.png)\n", 10 | "\n", 11 | "\n", 12 | "## Installation\n", 13 | "\n", 14 | "Simply,\n", 15 | "```\n", 16 | "pip install pandas\n", 17 | "```\n", 18 | "\n", 19 | "\n", 20 | "## Reading data from a CSV file\n", 21 | "\n", 22 | "You can read data from a CSV file using the ``read_csv`` function. By default, it assumes that the fields are comma-separated." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "# import pandas" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | ">The `imdb.csv` dataset contains Highest Rated IMDb \"Top 1000\" Titles." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "# load imdb dataset as pandas dataframe" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# show first 5 rows of imdb_df" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | ">The `bikes.csv` dataset contains information about the number of bicycles that used certain bicycle lanes in Montreal in the year 2012." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "# load bikes dataset as pandas dataframe" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "# show first 3 rows of bikes_df" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## Selecting columns\n", 89 | "\n", 90 | "When you read a CSV, you get a kind of object called a DataFrame, which is made up of rows and columns. You get columns out of a DataFrame the same way you get elements out of a dictionary." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "# list columns of imdb_df" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "# what are the datatypes of values in columns" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "# list first 5 movie titles" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "# show only movie title and genre" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "## Understanding columns\n", 134 | "\n", 135 | "On the inside, the type of a column is ``pd.Series`` and pandas Series are internally numpy arrays. If you add ``.values`` to the end of any Series, you'll get its internal **numpy array**." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "# show the type of duration column" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "# show duration values of movies as numpy arrays" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "## Applying functions to columns\n", 161 | "\n", 162 | "Use `.apply` function to apply any function to each element of a column." 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": null, 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "# convert all the movie titles to uppercase" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "## Plotting a column\n", 179 | "\n", 180 | "Use ``.plot()`` function!" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "# plot the bikers travelling to Berri1 over the year" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "# plot all the columns of bikes_df" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "## Value counts\n", 206 | "\n", 207 | "Get count of unique values in a particular column/Series." 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [ 216 | "# what are the unique genre in imdb_df?" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "# plotting value counts of unique genres as a bar chart" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": null, 231 | "metadata": {}, 232 | "outputs": [], 233 | "source": [ 234 | "# plotting value counts of unique genres as a pie chart" 235 | ] 236 | }, 237 | { 238 | "cell_type": "markdown", 239 | "metadata": {}, 240 | "source": [ 241 | "## Index\n", 242 | "\n", 243 | "### DATAFRAME = COLUMNS + INDEX + ND DATA\n", 244 | "\n", 245 | "### SERIES = INDEX + 1-D DATA\n", 246 | "\n", 247 | "**Index** or (**row labels**) is one of the fundamental data structure of pandas. It can be thought of as an **immutable array** and an **ordered set**.\n", 248 | "\n", 249 | "> Every row is uniquely identified by its index value." 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "# show index of bikes_df" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "metadata": {}, 265 | "outputs": [], 266 | "source": [ 267 | "# get row for date 2012-01-01" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "metadata": {}, 273 | "source": [ 274 | "#### To get row by integer index:\n", 275 | "\n", 276 | "Use ``.iloc[]`` for purely integer-location based indexing for selection by position." 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "metadata": {}, 283 | "outputs": [], 284 | "source": [ 285 | "# show 11th row of imdb_df using iloc" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "## Selecting rows where column has a particular value" 293 | ] 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": null, 298 | "metadata": {}, 299 | "outputs": [], 300 | "source": [ 301 | "# select only those movies where genre is adventure" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": null, 307 | "metadata": {}, 308 | "outputs": [], 309 | "source": [ 310 | "# which genre has highest number of movies with star rating above 8 and duration more than 130 minutes?" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": {}, 316 | "source": [ 317 | "## Adding a new column to DataFrame" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": null, 323 | "metadata": {}, 324 | "outputs": [], 325 | "source": [ 326 | "# add a weekday column to bikes_df" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "metadata": {}, 332 | "source": [ 333 | "## Deleting an existing column from DataFrame" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": null, 339 | "metadata": {}, 340 | "outputs": [], 341 | "source": [ 342 | "# remove column 'Unnamed: 1' from bikes_df" 343 | ] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "metadata": {}, 348 | "source": [ 349 | "## Deleting a row in DataFrame" 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": null, 355 | "metadata": {}, 356 | "outputs": [], 357 | "source": [ 358 | "# remove row no. 1 from bikes_df" 359 | ] 360 | }, 361 | { 362 | "cell_type": "markdown", 363 | "metadata": {}, 364 | "source": [ 365 | "## Group By\n", 366 | "\n", 367 | "Any groupby operation involves one of the following operations on the original object. They are −\n", 368 | "\n", 369 | "- Splitting the Object\n", 370 | "\n", 371 | "- Applying a function\n", 372 | "\n", 373 | "- Combining the results\n", 374 | "\n", 375 | "In many situations, we split the data into sets and we apply some functionality on each subset. In the apply functionality, we can perform the following operations −\n", 376 | "\n", 377 | "- **Aggregation** − computing a summary statistic\n", 378 | "\n", 379 | "- **Transformation** − perform some group-specific operation\n", 380 | "\n", 381 | "- **Filtration** − discarding the data with some condition" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": null, 387 | "metadata": {}, 388 | "outputs": [], 389 | "source": [ 390 | "# group imdb_df by movie genres" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": null, 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [ 399 | "# get crime movies group" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": null, 405 | "metadata": {}, 406 | "outputs": [], 407 | "source": [ 408 | "# get mean of movie durations for each group" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [ 417 | "# change duration of all movies in a particular genre to mean duration of the group" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [ 426 | "# drop groups/genres that do not have average movie duration greater than 120." 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": null, 432 | "metadata": {}, 433 | "outputs": [], 434 | "source": [ 435 | "# group weekday wise bikers count" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": null, 441 | "metadata": {}, 442 | "outputs": [], 443 | "source": [ 444 | "# get weekday wise biker count" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": null, 450 | "metadata": {}, 451 | "outputs": [], 452 | "source": [ 453 | "# plot weekday wise biker count for 'Berri1'" 454 | ] 455 | }, 456 | { 457 | "cell_type": "markdown", 458 | "metadata": {}, 459 | "source": [ 460 | "![](https://memegenerator.net/img/instances/500x/73988569/pythonpandas-is-easy-import-and-go.jpg)" 461 | ] 462 | } 463 | ], 464 | "metadata": { 465 | "kernelspec": { 466 | "display_name": "Python 3", 467 | "language": "python", 468 | "name": "python3" 469 | }, 470 | "language_info": { 471 | "codemirror_mode": { 472 | "name": "ipython", 473 | "version": 3 474 | }, 475 | "file_extension": ".py", 476 | "mimetype": "text/x-python", 477 | "name": "python", 478 | "nbconvert_exporter": "python", 479 | "pygments_lexer": "ipython3", 480 | "version": "3.6.5" 481 | } 482 | }, 483 | "nbformat": 4, 484 | "nbformat_minor": 2 485 | } 486 | -------------------------------------------------------------------------------- /3.FIFAWC18Analysis/data/goals.csv: -------------------------------------------------------------------------------- 1 | PlayerName,Minute,IdMatch,Type,TeamName,OppositionTeamName,Position,IsCaptain,GoalKeeperName,PlayerShirtNumber 2 | Iury GAZINSKY,12',300331503,2,Russia,Saudi Arabia,2,False,ABDULLAH ALMUAIOUF,8 3 | Denis CHERYSHEV,43',300331503,2,Russia,Saudi Arabia,2,False,ABDULLAH ALMUAIOUF,6 4 | Artem DZYUBA,71',300331503,2,Russia,Saudi Arabia,3,False,ABDULLAH ALMUAIOUF,22 5 | Denis CHERYSHEV,90'+1',300331503,2,Russia,Saudi Arabia,2,False,ABDULLAH ALMUAIOUF,6 6 | Aleksandr GOLOVIN,90'+4',300331503,2,Russia,Saudi Arabia,2,False,ABDULLAH ALMUAIOUF,17 7 | Jose GIMENEZ,89',300353632,2,Uruguay,Egypt,1,False,MOHAMED ELSHENAWY,2 8 | Aziz BOUHADDOUZ,90'+5',300331526,3,IR Iran,Morocco,3,False,,20 9 | CRISTIANO RONALDO,4',300331524,1,Portugal,Spain,3,True,David DE GEA,7 10 | CRISTIANO RONALDO,44',300331524,2,Portugal,Spain,3,True,David DE GEA,7 11 | CRISTIANO RONALDO,88',300331524,2,Portugal,Spain,3,True,David DE GEA,7 12 | Diego COSTA,24',300331524,2,Spain,Portugal,3,False,RUI PATRICIO,19 13 | Diego COSTA,55',300331524,2,Spain,Portugal,3,False,RUI PATRICIO,19 14 | NACHO,58',300331524,2,Spain,Portugal,1,False,RUI PATRICIO,4 15 | Antoine GRIEZMANN,58',300331533,1,France,Australia,3,False,Mathew RYAN,7 16 | Aziz BEHICH,81',300331533,3,France,Australia,1,False,,16 17 | Mile JEDINAK,62',300331533,1,Australia,France,2,True,Hugo LLORIS,15 18 | Sergio AGUERO,19',300331515,2,Argentina,Iceland,3,False,Hannes HALLDORSSON,19 19 | Alfred FINNBOGASON,23',300331515,2,Iceland,Argentina,3,False,Wilfredo CABALLERO,11 20 | Yussuf Yurary POULSEN,59',300331528,2,Denmark,Peru,3,False,Pedro GALLESE,20 21 | Oghenekaro ETEBO,32',300331523,3,Croatia,Nigeria,2,False,,8 22 | Luka MODRIC,71',300331523,1,Croatia,Nigeria,2,True,Francis UZOHO,10 23 | Aleksandar KOLAROV,56',300331529,2,Serbia,Costa Rica,1,True,Keylor NAVAS,11 24 | Hirving LOZANO,35',300331502,2,Mexico,Germany,3,False,Manuel NEUER,22 25 | PHILIPPE COUTINHO,20',300331525,2,Brazil,Switzerland,2,False,Yann SOMMER,11 26 | Steven ZUBER,50',300331525,2,Switzerland,Brazil,2,False,ALISSON,14 27 | Andreas GRANQVIST,65',300331499,1,Sweden,Korea Republic,1,True,JO Hyeonwoo,4 28 | Dries MERTENS,47',300331539,2,Belgium,Panama,3,False,Jaime PENEDO,14 29 | Romelu LUKAKU,69',300331539,2,Belgium,Panama,3,False,Jaime PENEDO,9 30 | Romelu LUKAKU,75',300331539,2,Belgium,Panama,3,False,Jaime PENEDO,9 31 | Ferjani SASSI,35',300331554,1,Tunisia,England,2,False,Jordan PICKFORD,13 32 | Harry KANE,11',300331554,2,England,Tunisia,3,True,Mouez HASSEN,9 33 | Harry KANE,90'+1',300331554,2,England,Tunisia,3,True,Farouk BEN MUSTAPHA,9 34 | Juan QUINTERO,39',300331550,2,Colombia,Japan,2,False,Eiji KAWASHIMA,20 35 | Shinji KAGAWA,6',300331550,1,Japan,Colombia,2,False,David OSPINA,10 36 | Yuya OSAKO,73',300331550,2,Japan,Colombia,3,False,David OSPINA,15 37 | Grzegorz KRYCHOWIAK,86',300331545,2,Poland,Senegal,2,False,Khadim NDIAYE,10 38 | Thiago CIONEK,37',300331545,3,Senegal,Poland,1,False,,4 39 | Mbaye NIANG,60',300331545,2,Senegal,Poland,3,False,Wojciech SZCZESNY,19 40 | AHMED FATHI,47',300331495,3,Russia,Egypt,1,True,,7 41 | Denis CHERYSHEV,59',300331495,2,Russia,Egypt,2,False,MOHAMED ELSHENAWY,6 42 | Artem DZYUBA,62',300331495,2,Russia,Egypt,3,False,MOHAMED ELSHENAWY,22 43 | MOHAMED SALAH,73',300331495,1,Egypt,Russia,3,False,Igor AKINFEEV,10 44 | CRISTIANO RONALDO,4',300331511,2,Portugal,Morocco,3,True,Monir EL KAJOUI,7 45 | Luis SUAREZ,23',300331530,2,Uruguay,Saudi Arabia,3,False,MOHAMMED ALOWAIS,9 46 | Diego COSTA,54',300331496,2,Spain,IR Iran,3,False,Ali BEIRANVAND,19 47 | Christian ERIKSEN,7',300331518,2,Denmark,Australia,2,False,Mathew RYAN,10 48 | Mile JEDINAK,38',300331518,1,Australia,Denmark,2,True,Kasper SCHMEICHEL,15 49 | Kylian MBAPPE,34',300331527,2,France,Peru,3,False,Pedro GALLESE,10 50 | Ante REBIC,53',300331513,2,Croatia,Argentina,3,False,Wilfredo CABALLERO,18 51 | Luka MODRIC,80',300331513,2,Croatia,Argentina,2,True,Wilfredo CABALLERO,10 52 | Ivan RAKITIC,90'+1',300331513,2,Croatia,Argentina,2,False,Wilfredo CABALLERO,7 53 | PHILIPPE COUTINHO,90'+1',300331540,2,Brazil,Costa Rica,2,False,Keylor NAVAS,11 54 | NEYMAR,90'+7',300331540,2,Brazil,Costa Rica,3,False,Keylor NAVAS,10 55 | Ahmed MUSA,49',300331497,2,Nigeria,Iceland,3,False,Hannes HALLDORSSON,7 56 | Ahmed MUSA,75',300331497,2,Nigeria,Iceland,3,False,Hannes HALLDORSSON,7 57 | Aleksandar MITROVIC,5',300340183,2,Serbia,Switzerland,3,False,Yann SOMMER,9 58 | Granit XHAKA,52',300340183,2,Switzerland,Serbia,2,False,Vladimir STOJKOVIC,10 59 | Xherdan SHAQIRI,90',300340183,2,Switzerland,Serbia,2,False,Vladimir STOJKOVIC,23 60 | Eden HAZARD,6',300331547,1,Belgium,Tunisia,3,True,Farouk BEN MUSTAPHA,10 61 | Romelu LUKAKU,16',300331547,2,Belgium,Tunisia,3,False,Farouk BEN MUSTAPHA,9 62 | Romelu LUKAKU,45'+3',300331547,2,Belgium,Tunisia,3,False,Farouk BEN MUSTAPHA,9 63 | Eden HAZARD,51',300331547,2,Belgium,Tunisia,3,True,Farouk BEN MUSTAPHA,10 64 | Michy BATSHUAYI,90',300331547,2,Belgium,Tunisia,3,False,Farouk BEN MUSTAPHA,21 65 | Dylan BRONN,18',300331547,2,Tunisia,Belgium,1,False,Thibaut COURTOIS,11 66 | Wahbi KHAZRI,90'+3',300331547,2,Tunisia,Belgium,3,True,Thibaut COURTOIS,10 67 | SON Heungmin,90'+3',300331549,2,Korea Republic,Mexico,3,False,Guillermo OCHOA,7 68 | Carlos VELA,26',300331549,1,Mexico,Korea Republic,3,False,JO Hyeonwoo,11 69 | Javier HERNANDEZ,66',300331549,2,Mexico,Korea Republic,3,False,JO Hyeonwoo,14 70 | Marco REUS,48',300331501,2,Germany,Sweden,3,False,Robin OLSEN,11 71 | Toni KROOS,90'+5',300331501,2,Germany,Sweden,2,False,Robin OLSEN,8 72 | Ola TOIVONEN,32',300331501,2,Sweden,Germany,3,False,Manuel NEUER,20 73 | John STONES,8',300331546,2,England,Panama,1,False,Jaime PENEDO,5 74 | Harry KANE,22',300331546,1,England,Panama,3,True,Jaime PENEDO,9 75 | Jesse LINGARD,36',300331546,2,England,Panama,2,False,Jaime PENEDO,7 76 | John STONES,40',300331546,2,England,Panama,1,False,Jaime PENEDO,5 77 | Harry KANE,45'+1',300331546,1,England,Panama,3,True,Jaime PENEDO,9 78 | Harry KANE,62',300331546,2,England,Panama,3,True,Jaime PENEDO,9 79 | Felipe BALOY,78',300331546,2,Panama,England,1,False,Jordan PICKFORD,23 80 | Takashi INUI,34',300331505,2,Japan,Senegal,2,False,Khadim NDIAYE,14 81 | Keisuke HONDA,78',300331505,2,Japan,Senegal,2,False,Khadim NDIAYE,4 82 | Sadio MANE,11',300331505,2,Senegal,Japan,3,True,Eiji KAWASHIMA,10 83 | Moussa WAGUE,71',300331505,2,Senegal,Japan,1,False,Eiji KAWASHIMA,22 84 | Yerry MINA,40',300331508,2,Colombia,Poland,1,False,Wojciech SZCZESNY,13 85 | Radamel FALCAO,70',300331508,2,Colombia,Poland,3,True,Wojciech SZCZESNY,9 86 | Juan CUADRADO,75',300331508,2,Colombia,Poland,2,False,Wojciech SZCZESNY,11 87 | Luis SUAREZ,10',300331516,2,Uruguay,Russia,3,False,Igor AKINFEEV,9 88 | Denis CHERYSHEV,23',300331516,3,Uruguay,Russia,2,False,,6 89 | Edinson CAVANI,90',300331516,2,Uruguay,Russia,3,False,Igor AKINFEEV,21 90 | SALMAN ALFARAJ,45'+6',300331509,1,Saudi Arabia,Egypt,2,False,ESSAM ELHADARY,7 91 | SALEM ALDAWSARI,90'+5',300331509,2,Saudi Arabia,Egypt,2,False,ESSAM ELHADARY,18 92 | MOHAMED SALAH,22',300331509,2,Egypt,Saudi Arabia,3,False,YASSER ALMOSAILEM,10 93 | ISCO,19',300340184,2,Spain,Morocco,2,False,Monir EL KAJOUI,22 94 | Iago ASPAS,90'+1',300340184,2,Spain,Morocco,3,False,Monir EL KAJOUI,17 95 | Khalid BOUTAIB,14',300340184,2,Morocco,Spain,3,False,David DE GEA,13 96 | Youssef EN NESYRI,81',300340184,2,Morocco,Spain,3,False,David DE GEA,19 97 | Karim ANSARIFARD,90'+3',300331500,1,IR Iran,Portugal,3,False,RUI PATRICIO,10 98 | RICARDO QUARESMA,45',300331500,2,Portugal,IR Iran,3,False,Ali BEIRANVAND,20 99 | Andre CARRILLO,18',300331506,2,Peru,Australia,3,False,Mathew RYAN,18 100 | Paolo GUERRERO,50',300331506,2,Peru,Australia,3,True,Mathew RYAN,9 101 | Victor MOSES,51',300331519,1,Nigeria,Argentina,3,False,Franco ARMANI,11 102 | Lionel MESSI,14',300331519,2,Argentina,Nigeria,3,True,Francis UZOHO,10 103 | Marcos ROJO,86',300331519,2,Argentina,Nigeria,1,False,Francis UZOHO,16 104 | Gylfi SIGURDSSON,76',300331510,1,Iceland,Croatia,2,False,Lovre KALINIC,10 105 | Milan BADELJ,53',300331510,2,Croatia,Iceland,2,False,Hannes HALLDORSSON,19 106 | Ivan PERISIC,90',300331510,2,Croatia,Iceland,3,False,Hannes HALLDORSSON,4 107 | KIM Younggwon,90'+3',300331532,2,Korea Republic,Germany,1,False,Manuel NEUER,19 108 | SON Heungmin,90'+6',300331532,2,Korea Republic,Germany,3,True,Manuel NEUER,7 109 | Ludwig AUGUSTINSSON,50',300331548,2,Sweden,Mexico,1,False,Guillermo OCHOA,6 110 | Andreas GRANQVIST,62',300331548,1,Sweden,Mexico,1,True,Guillermo OCHOA,4 111 | Edson ALVAREZ,74',300331548,3,Sweden,Mexico,1,False,,21 112 | PAULINHO,36',300331521,2,Brazil,Serbia,2,False,Vladimir STOJKOVIC,15 113 | THIAGO SILVA,68',300331521,2,Brazil,Serbia,1,False,Vladimir STOJKOVIC,2 114 | Blerim DZEMAILI,31',300331534,2,Switzerland,Costa Rica,2,False,Keylor NAVAS,15 115 | Josip DRMIC,88',300331534,2,Switzerland,Costa Rica,3,False,Keylor NAVAS,19 116 | Kendall WASTON,56',300331534,2,Costa Rica,Switzerland,1,False,Yann SOMMER,19 117 | Yann SOMMER,90'+3',300331534,3,Costa Rica,Switzerland,0,False,,1 118 | Jan BEDNAREK,59',300331507,2,Poland,Japan,1,False,Eiji KAWASHIMA,5 119 | Yerry MINA,74',300331553,2,Colombia,Senegal,1,False,Khadim NDIAYE,13 120 | Yassine MERIAH,33',300331520,3,Panama,Tunisia,1,False,,4 121 | Fakhreddine BEN YOUSSEF,51',300331520,2,Tunisia,Panama,3,False,Jaime PENEDO,8 122 | Wahbi KHAZRI,66',300331520,2,Tunisia,Panama,3,False,Jaime PENEDO,10 123 | Adnan JANUZAJ,51',300340182,2,Belgium,England,3,False,Jordan PICKFORD,18 124 | Antoine GRIEZMANN,13',300331537,1,France,Argentina,3,False,Franco ARMANI,7 125 | Benjamin PAVARD,57',300331537,2,France,Argentina,1,False,Franco ARMANI,2 126 | Kylian MBAPPE,64',300331537,2,France,Argentina,3,False,Franco ARMANI,10 127 | Kylian MBAPPE,68',300331537,2,France,Argentina,3,False,Franco ARMANI,10 128 | Angel DI MARIA,41',300331537,2,Argentina,France,2,False,Hugo LLORIS,11 129 | Gabriel MERCADO,48',300331537,2,Argentina,France,1,False,Hugo LLORIS,2 130 | Sergio AGUERO,90'+3',300331537,2,Argentina,France,3,False,Hugo LLORIS,19 131 | Edinson CAVANI,7',300331544,2,Uruguay,Portugal,3,False,RUI PATRICIO,21 132 | Edinson CAVANI,62',300331544,2,Uruguay,Portugal,3,False,RUI PATRICIO,21 133 | PEPE,55',300331544,2,Portugal,Uruguay,1,False,Fernando MUSLERA,3 134 | Sergey IGNASHEVICH,12',300331517,3,Spain,Russia,1,False,,4 135 | Andres INIESTA,120'+1',300331517,1,Spain,Russia,2,False,Igor AKINFEEV,6 136 | Gerard PIQUE,120'+2',300331517,1,Spain,Russia,1,False,Igor AKINFEEV,3 137 | Sergio RAMOS,120'+5',300331517,1,Spain,Russia,1,True,Igor AKINFEEV,15 138 | Artem DZYUBA,41',300331517,1,Russia,Spain,3,False,David DE GEA,22 139 | Fedor SMOLOV,120'+1',300331517,1,Russia,Spain,3,False,David DE GEA,10 140 | Sergey IGNASHEVICH,120'+3',300331517,1,Russia,Spain,1,False,David DE GEA,4 141 | Aleksandr GOLOVIN,120'+4',300331517,1,Russia,Spain,2,False,David DE GEA,17 142 | Denis CHERYSHEV,120'+6',300331517,1,Russia,Spain,2,False,David DE GEA,6 143 | Mario MANDZUKIC,4',300331498,2,Croatia,Denmark,3,False,Kasper SCHMEICHEL,17 144 | Andrej KRAMARIC,120'+4',300331498,1,Croatia,Denmark,3,False,Kasper SCHMEICHEL,9 145 | Luka MODRIC,120'+5',300331498,1,Croatia,Denmark,2,True,Kasper SCHMEICHEL,10 146 | Ivan RAKITIC,120'+9',300331498,1,Croatia,Denmark,2,False,Kasper SCHMEICHEL,7 147 | Mathias JORGENSEN,1',300331498,2,Denmark,Croatia,1,False,Danijel SUBASIC,13 148 | Simon KJAER,120'+3',300331498,1,Denmark,Croatia,1,True,Danijel SUBASIC,4 149 | Michael KROHN-DEHLI,120'+5',300331498,1,Denmark,Croatia,2,False,Danijel SUBASIC,2 150 | NEYMAR,51',300331535,2,Brazil,Mexico,3,False,Guillermo OCHOA,10 151 | ROBERTO FIRMINO,88',300331535,2,Brazil,Mexico,3,False,Guillermo OCHOA,20 152 | Jan VERTONGHEN,69',300331551,2,Belgium,Japan,1,False,Eiji KAWASHIMA,5 153 | Marouane FELLAINI,74',300331551,2,Belgium,Japan,2,False,Eiji KAWASHIMA,8 154 | Nacer CHADLI,90'+4',300331551,2,Belgium,Japan,2,False,Eiji KAWASHIMA,22 155 | Genki HARAGUCHI,48',300331551,2,Japan,Belgium,2,False,Thibaut COURTOIS,8 156 | Takashi INUI,52',300331551,2,Japan,Belgium,2,False,Thibaut COURTOIS,14 157 | Emil FORSBERG,66',300331514,2,Sweden,Switzerland,2,False,Yann SOMMER,10 158 | Yerry MINA,90'+3',300331542,2,Colombia,England,1,False,Jordan PICKFORD,13 159 | Radamel FALCAO,120'+1',300331542,1,Colombia,England,3,True,Jordan PICKFORD,9 160 | Juan CUADRADO,120'+3',300331542,1,Colombia,England,2,False,Jordan PICKFORD,11 161 | Luis MURIEL,120'+4',300331542,1,Colombia,England,3,False,Jordan PICKFORD,14 162 | Harry KANE,57',300331542,1,England,Colombia,3,True,David OSPINA,9 163 | Harry KANE,120'+2',300331542,1,England,Colombia,3,True,David OSPINA,9 164 | Marcus RASHFORD,120'+4',300331542,1,England,Colombia,3,False,David OSPINA,19 165 | Kieran TRIPPIER,120'+7',300331542,1,England,Colombia,1,False,David OSPINA,12 166 | Eric DIER,120'+8',300331542,1,England,Colombia,2,False,David OSPINA,4 167 | Raphael VARANE,40',300331543,2,France,Uruguay,1,False,Fernando MUSLERA,4 168 | Antoine GRIEZMANN,61',300331543,2,France,Uruguay,3,False,Fernando MUSLERA,7 169 | RENATO AUGUSTO,76',300331538,2,Brazil,Belgium,2,False,Thibaut COURTOIS,8 170 | FERNANDINHO,13',300331538,3,Belgium,Brazil,2,False,,17 171 | Kevin DE BRUYNE,31',300331538,2,Belgium,Brazil,2,False,ALISSON,7 172 | Harry MAGUIRE,30',300331541,2,England,Sweden,1,False,Robin OLSEN,6 173 | Dele ALLI,59',300331541,2,England,Sweden,2,False,Robin OLSEN,20 174 | Denis CHERYSHEV,31',300331504,2,Russia,Croatia,2,False,Danijel SUBASIC,6 175 | MARIO FERNANDES,115',300331504,2,Russia,Croatia,1,False,Danijel SUBASIC,2 176 | Alan DZAGOEV,120'+4',300331504,1,Russia,Croatia,2,False,Danijel SUBASIC,9 177 | Sergey IGNASHEVICH,120'+7',300331504,1,Russia,Croatia,1,False,Danijel SUBASIC,4 178 | Daler KUZIAEV,120'+8',300331504,1,Russia,Croatia,2,False,Danijel SUBASIC,7 179 | Andrej KRAMARIC,39',300331504,2,Croatia,Russia,3,False,Igor AKINFEEV,9 180 | Domagoj VIDA,101',300331504,2,Croatia,Russia,1,False,Igor AKINFEEV,21 181 | Marcelo BROZOVIC,120'+3',300331504,1,Croatia,Russia,2,False,Igor AKINFEEV,11 182 | Luka MODRIC,120'+6',300331504,1,Croatia,Russia,2,True,Igor AKINFEEV,10 183 | Domagoj VIDA,120'+8',300331504,1,Croatia,Russia,1,False,Igor AKINFEEV,21 184 | Ivan RAKITIC,120'+9',300331504,1,Croatia,Russia,2,False,Igor AKINFEEV,7 185 | Samuel UMTITI,51',300331531,2,France,Belgium,1,False,Thibaut COURTOIS,5 186 | Ivan PERISIC,68',300331522,2,Croatia,England,3,False,Jordan PICKFORD,4 187 | Mario MANDZUKIC,109',300331522,2,Croatia,England,3,False,Jordan PICKFORD,17 188 | Kieran TRIPPIER,5',300331522,2,England,Croatia,1,False,Danijel SUBASIC,12 189 | Thomas MEUNIER,4',300331536,2,Belgium,England,1,False,Jordan PICKFORD,15 190 | Eden HAZARD,82',300331536,2,Belgium,England,3,True,Jordan PICKFORD,10 191 | Mario MANDZUKIC,18',300331552,3,France,Croatia,3,False,,17 192 | Antoine GRIEZMANN,38',300331552,1,France,Croatia,3,False,Danijel SUBASIC,7 193 | Paul POGBA,59',300331552,2,France,Croatia,2,False,Danijel SUBASIC,6 194 | Kylian MBAPPE,65',300331552,2,France,Croatia,3,False,Danijel SUBASIC,10 195 | Ivan PERISIC,28',300331552,2,Croatia,France,3,False,Hugo LLORIS,4 196 | Mario MANDZUKIC,69',300331552,2,Croatia,France,3,False,Hugo LLORIS,17 197 | -------------------------------------------------------------------------------- /1.PandasBasics/data/bikes.csv: -------------------------------------------------------------------------------- 1 | Date;;Rachel / Papineau;Berri1;Maisonneuve_2;Maisonneuve_1;Brébeuf;Parc;PierDup;CSC (Côte Sainte-Catherine);Pont_Jacques_Cartier 2 | 01/01/2012;00:00;16;35;51;38;5;26;10;0;27 3 | 02/01/2012;00:00;43;83;153;68;11;53;6;1;21 4 | 03/01/2012;00:00;58;135;248;104;2;89;3;2;15 5 | 04/01/2012;00:00;61;144;318;116;2;111;8;1;19 6 | 05/01/2012;00:00;95;197;330;124;6;97;13;2;16 7 | 06/01/2012;00:00;75;146;244;98;4;86;4;0;17 8 | 07/01/2012;00:00;54;98;108;80;5;53;6;2;9 9 | 08/01/2012;00:00;63;95;98;62;13;64;11;1;23 10 | 09/01/2012;00:00;173;244;432;165;9;198;12;2;23 11 | 10/01/2012;00:00;241;397;563;238;6;275;18;3;46 12 | 11/01/2012;00:00;194;273;443;182;7;258;12;0;20 13 | 12/01/2012;00:00;63;157;261;134;3;137;9;1;15 14 | 13/01/2012;00:00;0;75;105;41;4;64;2;0;1 15 | 14/01/2012;00:00;1;32;56;54;0;19;0;0;3 16 | 15/01/2012;00:00;0;54;60;33;0;18;0;0;2 17 | 16/01/2012;00:00;0;168;312;136;8;137;1;2;1 18 | 17/01/2012;00:00;0;155;256;86;4;74;0;0;1 19 | 18/01/2012;00:00;0;139;188;66;2;68;3;0;20 20 | 19/01/2012;00:00;0;191;248;104;46;79;3;1;5 21 | 20/01/2012;00:00;1;161;217;96;4;67;1;4;13 22 | 21/01/2012;00:00;0;53;70;47;11;32;1;0;5 23 | 22/01/2012;00:00;0;71;73;41;20;35;5;0;29 24 | 23/01/2012;00:00;0;210;357;114;22;91;6;6;37 25 | 24/01/2012;00:00;0;299;444;189;9;174;4;1;20 26 | 25/01/2012;00:00;0;334;453;217;16;180;4;1;28 27 | 26/01/2012;00:00;1;306;495;215;3;191;0;0;21 28 | 27/01/2012;00:00;0;91;204;79;11;65;0;5;186 29 | 28/01/2012;00:00;1;80;123;61;3;33;9;1;34 30 | 29/01/2012;00:00;0;87;132;65;6;40;7;1;20 31 | 30/01/2012;00:00;0;219;371;146;6;152;2;0;38 32 | 31/01/2012;00:00;0;186;324;109;7;122;0;1;4 33 | 01/02/2012;00:00;0;138;271;100;10;71;5;0;4 34 | 02/02/2012;00:00;2;217;345;134;7;128;2;5;4 35 | 03/02/2012;00:00;1;174;301;103;2;111;1;1;8 36 | 04/02/2012;00:00;0;84;119;53;16;44;8;0;59 37 | 05/02/2012;00:00;0;72;133;46;11;54;7;0;58 38 | 06/02/2012;00:00;0;248;425;136;5;167;10;1;19 39 | 07/02/2012;00:00;0;316;516;209;12;225;9;0;22 40 | 08/02/2012;00:00;1;271;503;202;6;215;4;0;27 41 | 09/02/2012;00:00;0;342;471;227;6;231;11;0;24 42 | 10/02/2012;00:00;2;303;478;206;13;216;6;1;10 43 | 11/02/2012;00:00;0;71;112;63;12;49;3;0;22 44 | 12/02/2012;00:00;0;78;91;36;4;53;5;0;7 45 | 13/02/2012;00:00;0;211;408;175;13;207;4;0;3 46 | 14/02/2012;00:00;1;318;504;186;6;243;9;0;11 47 | 15/02/2012;00:00;1;307;491;180;8;232;5;0;26 48 | 16/02/2012;00:00;0;386;569;212;3;295;10;1;16 49 | 17/02/2012;00:00;1;332;496;237;15;260;11;3;6 50 | 18/02/2012;00:00;0;220;280;159;7;134;30;1;68 51 | 19/02/2012;00:00;2;169;205;110;7;113;13;3;38 52 | 20/02/2012;00:00;10;303;470;224;17;243;14;2;30 53 | 21/02/2012;00:00;6;441;503;292;12;286;10;5;10 54 | 22/02/2012;00:00;3;375;501;263;7;264;12;10;29 55 | 23/02/2012;00:00;13;397;528;293;12;329;22;10;21 56 | 24/02/2012;00:00;13;243;313;187;13;137;4;4;25 57 | 25/02/2012;00:00;5;62;52;48;1;18;2;0;2 58 | 26/02/2012;00:00;0;78;47;76;2;35;4;0;14 59 | 27/02/2012;00:00;5;119;298;94;9;134;3;4;8 60 | 28/02/2012;00:00;3;195;350;158;22;168;9;0;12 61 | 29/02/2012;00:00;4;242;446;164;15;190;7;0;11 62 | 01/03/2012;00:00;14;92;199;56;46;63;0;0;14 63 | 02/03/2012;00:00;1;143;283;56;31;77;7;0;2 64 | 03/03/2012;00:00;0;82;133;65;2;47;2;0;12 65 | 04/03/2012;00:00;0;107;138;79;0;60;15;2;6 66 | 05/03/2012;00:00;2;155;363;114;88;157;8;1;6 67 | 06/03/2012;00:00;0;269;437;192;4;170;10;0;11 68 | 07/03/2012;00:00;0;438;715;290;7;266;28;3;35 69 | 08/03/2012;00:00;9;348;530;238;2;270;9;6;34 70 | 09/03/2012;00:00;38;371;575;279;9;268;8;8;23 71 | 10/03/2012;00:00;58;182;296;162;16;165;0;13;89 72 | 11/03/2012;00:00;285;380;540;253;12;289;0;60;163 73 | 12/03/2012;00:00;548;802;1265;618;12;747;0;179;145 74 | 13/03/2012;00:00;325;442;769;321;9;425;0;145;72 75 | 14/03/2012;00:00;336;469;739;313;11;451;0;146;96 76 | 15/03/2012;00:00;565;724;1021;562;10;631;63;244;427 77 | 16/03/2012;00:00;422;423;695;305;16;419;9;149;234 78 | 17/03/2012;00:00;1008;681;872;422;13;468;334;287;637 79 | 18/03/2012;00:00;2477;1940;1923;1036;162;1021;1128;856;23092 80 | 19/03/2012;00:00;2058;1821;2581;1278;104;1609;506;1024;12593 81 | 20/03/2012;00:00;2609;2481;3130;1709;243;1955;762;1261;1569 82 | 21/03/2012;00:00;2846;2829;3510;1893;283;2225;993;1558;1834 83 | 22/03/2012;00:00;2254;2195;2654;1640;150;1958;548;1030;1360 84 | 23/03/2012;00:00;2325;2115;2955;1512;125;1791;663;1143;1270 85 | 24/03/2012;00:00;1035;753;1001;517;54;635;277;336;481 86 | 25/03/2012;00:00;723;520;691;309;49;427;145;243;264 87 | 26/03/2012;00:00;1168;968;1493;729;105;965;130;564;477 88 | 27/03/2012;00:00;1207;1049;1576;774;75;972;163;517;450 89 | 28/03/2012;00:00;529;435;709;329;35;486;28;179;176 90 | 29/03/2012;00:00;937;878;1264;646;88;807;78;406;377 91 | 30/03/2012;00:00;1288;1157;1596;910;146;957;196;529;594 92 | 31/03/2012;00:00;1370;980;1083;587;175;706;524;499;656 93 | 01/04/2012;00:00;1086;662;824;442;242;471;168;341;374 94 | 02/04/2012;00:00;2122;1937;2853;1537;1260;1614;394;967;1065 95 | 03/04/2012;00:00;2450;2416;3556;1791;1511;1880;513;1078;1235 96 | 04/04/2012;00:00;2242;2211;2956;1674;1161;1666;274;933;911 97 | 05/04/2012;00:00;2463;2424;3273;1823;1281;1699;355;1036;1030 98 | 06/04/2012;00:00;2138;1633;1913;1045;1100;975;621;650;876 99 | 07/04/2012;00:00;1566;1208;1445;739;716;709;598;494;622 100 | 08/04/2012;00:00;1533;1164;1333;621;786;704;792;560;761 101 | 09/04/2012;00:00;1001;828;1048;560;412;605;65;298;230 102 | 10/04/2012;00:00;2108;2183;2932;1588;1174;1736;252;909;875 103 | 11/04/2012;00:00;2311;2328;3122;1765;1333;1843;330;1049;966 104 | 12/04/2012;00:00;3213;3064;4076;2306;1646;2280;590;1483;1474 105 | 13/04/2012;00:00;3728;3341;4465;2565;1916;2358;922;1505;1689 106 | 14/04/2012;00:00;3428;2890;2994;1639;1792;1594;1284;1072;1345 107 | 15/04/2012;00:00;3604;2554;2954;1637;1810;1559;1846;1210;1403 108 | 16/04/2012;00:00;3616;3643;4830;2723;2081;2677;1061;1841;1679 109 | 17/04/2012;00:00;3333;3539;4592;2636;1740;2450;544;1616;1439 110 | 18/04/2012;00:00;3542;3570;4655;2759;1852;2534;706;1751;1631 111 | 19/04/2012;00:00;3929;4231;5311;3235;2222;2877;1206;2010;1964 112 | 20/04/2012;00:00;2065;2087;2922;1529;869;1531;170;800;597 113 | 21/04/2012;00:00;755;533;710;398;311;408;50;212;199 114 | 22/04/2012;00:00;1779;1853;1331;1224;761;654;198;487;427 115 | 23/04/2012;00:00;846;623;1076;544;369;612;27;315;221 116 | 24/04/2012;00:00;1753;1810;2379;1355;888;1286;188;720;565 117 | 25/04/2012;00:00;2454;2966;3444;2228;1188;1800;445;1023;972 118 | 26/04/2012;00:00;2438;2751;3546;2196;1193;1789;381;1069;1037 119 | 27/04/2012;00:00;1899;1986;2586;1526;875;1298;139;743;551 120 | 28/04/2012;00:00;2323;1684;1908;1190;929;931;523;628;710 121 | 29/04/2012;00:00;2493;1970;2077;1212;1152;1062;702;765;915 122 | 30/04/2012;00:00;3541;3610;4675;2825;1885;2446;851;1572;1689 123 | 01/05/2012;00:00;1960;1986;2766;1722;1020;1516;195;815;763 124 | 02/05/2012;00:00;3501;3724;4731;2885;1883;2508;876;1677;1809 125 | 03/05/2012;00:00;3603;3698;4943;3001;1793;2577;731;1618;1538 126 | 04/05/2012;00:00;2631;2511;3717;2058;1279;1823;380;1163;845 127 | 05/05/2012;00:00;4108;3492;3696;2106;2075;1779;1677;1366;1576 128 | 06/05/2012;00:00;4633;3411;3346;1815;2302;1879;2036;1525;1731 129 | 07/05/2012;00:00;5253;5552;6355;3959;3005;3416;1848;2573;2680 130 | 08/05/2012;00:00;1383;1241;1729;991;688;1007;119;625;487 131 | 09/05/2012;00:00;3129;3297;4343;2700;1704;2340;737;1545;1294 132 | 10/05/2012;00:00;2437;2755;4056;2130;1250;2075;399;1227;1064 133 | 11/05/2012;00:00;4499;4639;5713;3663;2384;2888;1260;1803;1695 134 | 12/05/2012;00:00;4855;3854;3894;2429;2309;1805;2268;1457;2092 135 | 13/05/2012;00:00;3496;2741;3086;1703;1901;1592;1394;1223;7175 136 | 14/05/2012;00:00;5775;6189;7006;4402;3278;3868;2215;2709;3237 137 | 15/05/2012;00:00;3765;3964;5088;3144;1972;2650;975;1773;1454 138 | 16/05/2012;00:00;4348;4947;5882;3681;2409;3057;1332;2178;1893 139 | 17/05/2012;00:00;4988;5351;6551;4182;2657;3408;1631;2441;2230 140 | 18/05/2012;00:00;5273;5980;6646;4415;2911;3196;1711;2241;2365 141 | 19/05/2012;00:00;5293;4732;4673;2807;2723;1966;2914;1454;2628 142 | 20/05/2012;00:00;5539;5255;4462;2730;2787;2182;4241;1663;3073 143 | 21/05/2012;00:00;5053;5129;4169;2672;2737;2044;3413;1646;2163 144 | 22/05/2012;00:00;2069;2315;2599;1847;1225;1610;251;938;679 145 | 23/05/2012;00:00;4798;5974;7281;4407;2937;3737;1826;2650;2524 146 | 24/05/2012;00:00;5209;6485;7600;4600;3255;3792;2062;2653;2639 147 | 25/05/2012;00:00;5174;5670;6677;4096;532;3341;1953;2205;2056 148 | 26/05/2012;00:00;5443;4981;5017;2936;;2373;3455;1622;2571 149 | 27/05/2012;00:00;5168;4391;4559;2578;;2073;2886;1525;2364 150 | 28/05/2012;00:00;3894;4263;5789;3449;;2898;1027;1962;1790 151 | 29/05/2012;00:00;2731;3152;3912;2325;;1933;475;1184;2012 152 | 30/05/2012;00:00;5172;6475;7644;4806;;3817;2454;2722;2758 153 | 31/05/2012;00:00;4410;5123;6632;3985;;3205;1389;2177;1995 154 | 01/06/2012;00:00;6595;6092;7181;4110;;3895;1692;2604;2579 155 | 02/06/2012;00:00;1436;904;1259;630;;628;71;392;772 156 | 03/06/2012;00:00;4936;2763;3774;2020;;2324;1312;1897;1634 157 | 04/06/2012;00:00;3090;2718;4266;2095;;2168;333;1408;2523 158 | 05/06/2012;00:00;5348;5843;7314;3927;;3786;1232;2721;1692 159 | 06/06/2012;00:00;5269;6047;7825;4273;;3987;1223;2724;2746 160 | 07/06/2012;00:00;5724;6235;8220;4670;;3972;1019;2607;2760 161 | 08/06/2012;00:00;4474;4190;5898;3303;;3001;623;1833;2996 162 | 09/06/2012;00:00;6026;5185;5589;3418;;2451;1551;1672;2101 163 | 10/06/2012;00:00;6170;5083;4761;2905;;2328;1833;1812;2880 164 | 11/06/2012;00:00;5721;6203;7005;4333;;3757;1264;2577;3020 165 | 12/06/2012;00:00;3030;3346;4220;2362;;2381;589;1556;1421 166 | 13/06/2012;00:00;5887;6221;7312;4374;;3825;1968;2792;2863 167 | 14/06/2012;00:00;6243;6899;7942;4809;;4223;2386;2978;2996 168 | 15/06/2012;00:00;6491;7104;7685;4999;;4053;2293;2469;2756 169 | 16/06/2012;00:00;5537;5412;4900;3099;;2337;3280;1651;2446 170 | 17/06/2012;00:00;5128;4597;4077;2082;;2020;3453;1552;2879 171 | 18/06/2012;00:00;5496;5918;6835;3582;;3960;2455;2703;3012 172 | 19/06/2012;00:00;5015;5389;6673;3447;;3438;1711;2360;2529 173 | 20/06/2012;00:00;4852;5715;6857;3524;;3510;2363;2402;2734 174 | 21/06/2012;00:00;4957;5186;6686;3297;;3272;2265;2195;2503 175 | 22/06/2012;00:00;5263;5404;6666;3612;;3252;2009;1934;4577 176 | 23/06/2012;00:00;4824;3738;3991;1842;;1910;2585;1326;2520 177 | 24/06/2012;00:00;4581;3334;2977;1423;;1510;3634;1152;2907 178 | 25/06/2012;00:00;3283;2249;3020;1374;;1440;1349;1077;2782 179 | 26/06/2012;00:00;3223;3322;4314;2139;;2193;620;1435;1259 180 | 27/06/2012;00:00;2897;3152;4212;2142;;2134;536;1322;1137 181 | 28/06/2012;00:00;5175;6098;6886;4411;;3523;2415;2381;2641 182 | 29/06/2012;00:00;5332;5783;6662;4004;;3090;2109;1935;2493 183 | 30/06/2012;00:00;4527;4728;4234;3007;;1822;2870;1359;2743 184 | 01/07/2012;00:00;4522;4738;3952;2911;;1777;3732;1343;2426 185 | 02/07/2012;00:00;4464;4143;3977;2658;;1883;2783;1397;2048 186 | 03/07/2012;00:00;5462;6708;7399;4398;;3896;2606;2634;3251 187 | 04/07/2012;00:00;4493;5147;5824;3591;;3070;1246;2038;2029 188 | 05/07/2012;00:00;5153;6703;7763;4830;;3816;2746;2603;2112 189 | 06/07/2012;00:00;5610;5963;6955;4137;;3387;2248;2095;2414 190 | 07/07/2012;00:00;4939;5445;5000;3802;;2132;3156;1289;2286 191 | 08/07/2012;00:00;5535;4677;4457;2407;;2089;4386;1497;3331 192 | 09/07/2012;00:00;4987;5669;6765;3524;;3577;2599;2330;2953 193 | 10/07/2012;00:00;5952;6518;7447;4064;;3749;2822;2625;3294 194 | 11/07/2012;00:00;5474;6424;7366;3921;;3781;2779;2548;4153 195 | 12/07/2012;00:00;5140;6178;7202;3772;;3687;2433;2371;2565 196 | 13/07/2012;00:00;5185;5515;6508;3525;;3088;2219;2005;2488 197 | 14/07/2012;00:00;4252;4227;4281;2441;;1562;2900;1244;2378 198 | 15/07/2012;00:00;3545;3008;3406;1798;;1449;2034;1060;1945 199 | 16/07/2012;00:00;4379;4822;6053;3141;;2965;1703;2092;2323 200 | 17/07/2012;00:00;2641;2761;3799;2001;;1700;569;1046;783 201 | 18/07/2012;00:00;5884;6184;7324;3750;;3654;2813;2589;3037 202 | 19/07/2012;00:00;5665;6322;7708;3996;;3777;2647;2397;1345 203 | 20/07/2012;00:00;5775;5812;6952;3744;;3316;2538;2088;3096 204 | 21/07/2012;00:00;4848;5118;4683;2957;;1821;3835;1419;2460 205 | 22/07/2012;00:00;4787;4938;4086;2683;;1788;2960;1238;2723 206 | 23/07/2012;00:00;3475;3858;4911;2420;;2534;1461;1660;2130 207 | 24/07/2012;00:00;4694;5252;6746;3465;;3317;2170;2318;2700 208 | 25/07/2012;00:00;5059;6107;7065;3786;;3622;3132;2593;3564 209 | 26/07/2012;00:00;4383;5591;6490;4174;;3208;1595;2043;2332 210 | 27/07/2012;00:00;5295;5733;6870;3658;;3275;2653;1948;2959 211 | 28/07/2012;00:00;4631;4115;4501;2504;;1767;2468;1345;2653 212 | 29/07/2012;00:00;4906;4207;4237;1791;;1905;3731;1332;3232 213 | 30/07/2012;00:00;5100;5225;6210;2975;;3196;2564;2285;3205 214 | 31/07/2012;00:00;4468;5422;6707;3145;;3222;2505;2185;3023 215 | 01/08/2012;00:00;3889;4644;5852;2783;;2810;1481;1842;2197 216 | 02/08/2012;00:00;4828;5700;6968;3340;;3329;2643;2361;2957 217 | 03/08/2012;00:00;5031;5612;6451;3306;;2789;3195;1915;4858 218 | 04/08/2012;00:00;4467;4213;4407;2019;;1769;2939;1305;3994 219 | 05/08/2012;00:00;2268;1838;2300;1100;;970;1066;630;2098 220 | 06/08/2012;00:00;4604;5247;6375;3193;;3187;2274;2277;3130 221 | 07/08/2012;00:00;4903;5987;6833;3622;;3480;2780;2410;3186 222 | 08/08/2012;00:00;4771;5516;6883;3365;;3403;2226;2313;2926 223 | 09/08/2012;00:00;3636;4117;5366;2601;;2656;1471;1802;2025 224 | 10/08/2012;00:00;2456;2408;3318;1727;;1641;440;934;927 225 | 11/08/2012;00:00;2608;2454;2626;1589;;1043;1340;815;1456 226 | 12/08/2012;00:00;4178;3993;3433;1937;;1719;2988;1338;2721 227 | 13/08/2012;00:00;4842;4934;5934;3124;;3151;2090;2298;2868 228 | 14/08/2012;00:00;4362;5339;6331;3571;;3260;1456;2322;2883 229 | 15/08/2012;00:00;3877;4307;4953;2936;;2686;970;1882;2061 230 | 16/08/2012;00:00;4943;6055;6564;3898;;3366;1549;2538;3158 231 | 17/08/2012;00:00;4154;4239;4983;3099;;2581;586;1777;1999 232 | 18/08/2012;00:00;4359;4443;3853;2505;;1864;1229;1333;2159 233 | 19/08/2012;00:00;4478;4613;3771;2605;;1758;1683;1408;2369 234 | 20/08/2012;00:00;5201;5342;6086;3521;;3332;1439;2474;3140 235 | 21/08/2012;00:00;5640;5791;6705;4063;;3369;2353;2508;3265 236 | 22/08/2012;00:00;5154;6532;7050;4513;;3774;2391;2671;3231 237 | 23/08/2012;00:00;5010;5447;6789;3807;;3573;1864;2482;2900 238 | 24/08/2012;00:00;5299;5695;6714;3778;;3312;2178;2394;2881 239 | 25/08/2012;00:00;4833;4229;4118;2358;;1726;2558;1305;2114 240 | 26/08/2012;00:00;4536;3953;3545;2118;;1750;2932;1318;2570 241 | 27/08/2012;00:00;3598;4318;5189;3098;;2762;1010;2273;2130 242 | 28/08/2012;00:00;4720;5809;6310;3966;;3420;1629;2794;2645 243 | 29/08/2012;00:00;5342;6337;7017;4370;;3759;2152;3092;3147 244 | 30/08/2012;00:00;5202;5999;6787;4199;;3481;1796;2910;2877 245 | 31/08/2012;00:00;4188;4130;5061;2999;;2541;875;1868;1658 246 | 01/09/2012;00:00;3845;3922;3915;2371;;1887;2801;1225;2370 247 | 02/09/2012;00:00;4247;3701;3811;2093;;1788;2959;1232;2338 248 | 03/09/2012;00:00;4709;4160;3716;2233;;1620;3783;1532;2724 249 | 04/09/2012;00:00;3868;4226;5271;3057;;3006;894;1934;1859 250 | 05/09/2012;00:00;4491;5669;7116;3861;;4061;1383;2722;2369 251 | 06/09/2012;00:00;4732;5883;7514;3967;;4014;1498;2883;2644 252 | 07/09/2012;00:00;6104;6193;7347;4153;;3886;2051;2720;2874 253 | 08/09/2012;00:00;2626;2138;2712;1467;;898;801;1192;1146 254 | 09/09/2012;00:00;4355;3310;3459;1828;;2668;2118;1810;2107 255 | 10/09/2012;00:00;4984;5073;6638;3718;;3849;1271;2792;2440 256 | 11/09/2012;00:00;5451;6023;7147;4081;;4314;1484;2913;2623 257 | 12/09/2012;00:00;5697;6357;7302;4209;;4510;1981;3124;3063 258 | 13/09/2012;00:00;5742;6513;7529;4369;;4494;1986;3076;2943 259 | 14/09/2012;00:00;4918;5203;6084;3480;;3574;1524;2257;2276 260 | 15/09/2012;00:00;3426;3357;3108;1900;;1593;1268;1100;1478 261 | 16/09/2012;00:00;3696;3624;3031;1614;;1852;2348;1231;1849 262 | 17/09/2012;00:00;4788;5295;6579;3670;;4076;1704;2658;2613 263 | 18/09/2012;00:00;2377;2532;3247;1695;;2275;388;1277;1038 264 | 19/09/2012;00:00;4189;4662;5755;3176;;3738;840;2351;1860 265 | 20/09/2012;00:00;5119;5255;6352;3615;;3991;1391;2496;2414 266 | 21/09/2012;00:00;3886;4019;4731;2911;;2945;889;1821;1662 267 | 22/09/2012;00:00;1974;1524;1703;1073;;971;365;656;588 268 | 23/09/2012;00:00;3321;2304;2560;1496;;1470;984;1093;1507 269 | 24/09/2012;00:00;4683;4560;5744;3117;;3705;1100;2246;2043 270 | 25/09/2012;00:00;4420;5045;5857;3273;;3712;1007;2236;1959 271 | 26/09/2012;00:00;3721;3948;4751;2720;;3119;650;1873;1561 272 | 27/09/2012;00:00;4598;5115;5985;3465;;3704;1152;2288;2196 273 | 28/09/2012;00:00;4361;4664;5377;3209;;3309;1133;2134;1905 274 | 29/09/2012;00:00;2267;1882;1956;1206;;1062;442;755;780 275 | 30/09/2012;00:00;1162;867;946;513;;520;133;359;320 276 | 01/10/2012;00:00;2987;3264;3837;2184;;2582;397;1576;1161 277 | 02/10/2012;00:00;4497;5154;5847;3281;;3732;1229;2525;2135 278 | 03/10/2012;00:00;3941;4676;5476;3191;;3415;858;2377;1711 279 | 04/10/2012;00:00;3418;4034;4852;2705;;3066;555;2025;1501 280 | 05/10/2012;00:00;4088;4148;4703;2799;;2844;1035;1977;1703 281 | 06/10/2012;00:00;1775;1296;1578;933;;776;236;469;4229 282 | 07/10/2012;00:00;2052;1589;1627;922;;860;695;660;836 283 | 08/10/2012;00:00;2502;1854;1810;987;;1040;1115;880;292 284 | 09/10/2012;00:00;4078;4783;5138;3026;;3418;927;2210;255 285 | 10/10/2012;00:00;2703;3111;3683;2081;;2608;560;1537;0 286 | 11/10/2012;00:00;3457;3757;4694;2569;;3034;558;1857;0 287 | 12/10/2012;00:00;3224;3167;4054;2261;;2564;448;1460;0 288 | 13/10/2012;00:00;2309;1773;2111;1205;;1183;681;802;0 289 | 14/10/2012;00:00;952;583;839;443;;503;65;287;0 290 | 15/10/2012;00:00;3183;3298;4202;2165;;2754;560;1678;0 291 | 16/10/2012;00:00;3593;3748;4676;2684;;2997;554;1858;0 292 | 17/10/2012;00:00;3834;4097;4847;2645;;3063;728;1964;0 293 | 18/10/2012;00:00;4245;4685;5548;3129;;3477;1108;2292;0 294 | 19/10/2012;00:00;1486;1292;1659;885;;1209;111;597;0 295 | 20/10/2012;00:00;2243;2010;2265;1323;;1213;797;748;0 296 | 21/10/2012;00:00;1648;1275;1773;869;;898;242;609;0 297 | 22/10/2012;00:00;3721;3657;4810;2495;;3023;757;1819;0 298 | 23/10/2012;00:00;3554;4174;5212;2795;;3233;795;1997;0 299 | 24/10/2012;00:00;3622;3741;4901;2625;;3035;649;1868;0 300 | 25/10/2012;00:00;3767;3745;5015;2528;;3017;631;1815;0 301 | 26/10/2012;00:00;4578;4285;5269;2754;;3000;1456;1987;0 302 | 27/10/2012;00:00;2471;1865;2435;1244;;1193;618;792;0 303 | 28/10/2012;00:00;1876;1296;1770;910;;955;387;697;0 304 | 29/10/2012;00:00;2795;2916;3764;2071;;2440;411;1458;0 305 | 30/10/2012;00:00;2790;2894;3525;2007;;2255;338;1251;0 306 | 31/10/2012;00:00;2570;2630;3454;1835;;2220;245;1294;0 307 | 01/11/2012;00:00;2461;2408;3069;1701;;2076;165;1208;0 308 | 02/11/2012;00:00;1888;1575;2291;1109;;1392;97;737;0 309 | 03/11/2012;00:00;1302;844;1129;612;;713;105;380;0 310 | 04/11/2012;00:00;1374;965;1283;710;;692;197;446;0 311 | 05/11/2012;00:00;2430;2255;3216;1705;;2143;179;1170;0 312 | 06/11/2012;00:00;2679;2529;3365;1804;;1999;197;1201;0 313 | 07/11/2012;00:00;2391;2324;3227;1745;;2079;177;1116;0 314 | 08/11/2012;00:00;2436;2267;3279;1716;;2032;167;1113;0 315 | 09/11/2012;00:00;2376;2314;3046;1734;;1727;228;1012;0 316 | 10/11/2012;00:00;1801;1358;1531;941;;808;210;512;0 317 | 11/11/2012;00:00;1455;1080;1321;761;;769;239;502;0 318 | 12/11/2012;00:00;2954;3019;3978;2087;;2374;639;1409;0 319 | 13/11/2012;00:00;2452;2290;3303;1722;;1994;113;1177; 320 | 14/11/2012;00:00;2602;2580;3388;1811;;2125;218;1206; 321 | 15/11/2012;00:00;2411;2242;3042;1644;;1963;140;1119; 322 | 16/11/2012;00:00;2083;1861;2417;1325;;1550;200;885; 323 | 17/11/2012;00:00;1393;977;1211;685;;706;157;429; 324 | 18/11/2012;00:00;1271;886;1039;520;;603;207;390; 325 | 19/11/2012;00:00;2014;1674;2427;1220;;1699;194;940; 326 | 20/11/2012;00:00;2265;1886;2598;1405;;1726;181;992; 327 | 21/11/2012;00:00;2269;1997;2729;1485;;1784;260;1110; 328 | 22/11/2012;00:00;2382;2197;2891;1418;;1868;286;1143; 329 | 23/11/2012;00:00;2033;1716;2337;1152;;1451;194;896; 330 | 24/11/2012;00:00;998;605;879;413;;482;69;301; 331 | 25/11/2012;00:00;866;523;719;302;;390;38;229; 332 | 26/11/2012;00:00;1656;1467;1956;1007;;1346;89;663; 333 | 27/11/2012;00:00;1820;1686;2135;1090;;1413;100;786; 334 | 28/11/2012;00:00;1602;1395;1804;920;;1207;65;685; 335 | 29/11/2012;00:00;886;681;1011;483;;504;26;267; 336 | 30/11/2012;00:00;784;693;937;482;;536;13;148; 337 | 01/12/2012;00:00;468;293;372;219;;226;26;55; 338 | 02/12/2012;00:00;393;324;395;115;;218;35;100; 339 | 03/12/2012;00:00;1499;1286;1753;876;;1184;116;653; 340 | 04/12/2012;00:00;1502;1264;1654;882;;1139;97;639; 341 | 05/12/2012;00:00;1402;1204;1573;846;;980;40;585; 342 | 06/12/2012;00:00;1392;1252;1595;811;;1036;76;544; 343 | 07/12/2012;00:00;1384;1151;1574;742;;903;65;466; 344 | 08/12/2012;00:00;546;382;459;265;;298;26;192; 345 | 09/12/2012;00:00;642;427;513;272;;314;52;180; 346 | 10/12/2012;00:00;323;245;375;148;;126;5;17; 347 | 11/12/2012;00:00;598;517;711;336;;308;20;0; 348 | 12/12/2012;00:00;699;598;852;417;;360;14;1; 349 | 13/12/2012;00:00;781;655;844;400;;431;26;1; 350 | 14/12/2012;00:00;856;738;878;457;;474;41;2; 351 | 15/12/2012;00:00;464;335;375;205;;185;10;0; 352 | 16/12/2012;00:00;251;177;205;100;;96;10;0; 353 | 17/12/2012;00:00;204;236;355;135;;51;11;0; 354 | 18/12/2012;00:00;169;242;256;125;;21;9;0; 355 | 19/12/2012;00:00;383;346;456;181;;162;1;0; 356 | 20/12/2012;00:00;434;433;538;262;;166;9;0; 357 | 21/12/2012;00:00;208;178;249;86;;56;6;1; 358 | 22/12/2012;00:00;62;84;71;35;;16;1;0; 359 | 23/12/2012;00:00;87;82;50;39;;19;4;0; 360 | 24/12/2012;00:00;101;51;92;33;;25;1;0; 361 | 25/12/2012;00:00;59;26;26;22;;8;17;0; 362 | 26/12/2012;00:00;95;49;74;48;;20;7;0; 363 | 27/12/2012;00:00;8;12;7;4;;1;2;0; 364 | 28/12/2012;00:00;0;35;3;38;;0;0;0; 365 | 29/12/2012;00:00;0;27;8;42;;9;0;0; 366 | 30/12/2012;00:00;0;5;1;5;;6;0;0; 367 | 31/12/2012;00:00;0;4;3;8;;12;0;0; 368 | -------------------------------------------------------------------------------- /3.FIFAWC18Analysis/DataCollection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![](https://i.imgur.com/A3Cxp7P.png)\n", 8 | "\n", 9 | "## FIFA official API\n", 10 | "\n", 11 | "https://api.fifa.com\n", 12 | "\n", 13 | "### API Doc\n", 14 | "\n", 15 | "https://api.qa.fifa.com/Help\n", 16 | "\n", 17 | ">Our goal is to fetch world cup 2018 data through this API." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": {}, 24 | "outputs": [], 25 | "source": [ 26 | "import csv\n", 27 | "import json\n", 28 | "import requests\n", 29 | "from tqdm import tqdm" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "def write_to_csv(data, filename, fieldnames):\n", 39 | " with open(filename, \"w\") as f:\n", 40 | " csv_dict_writer = csv.DictWriter(f, fieldnames=fieldnames)\n", 41 | " csv_dict_writer.writeheader()\n", 42 | " csv_dict_writer.writerows(data)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Get list of available competitions\n", 50 | "\n", 51 | "https://api.fifa.com/api/v1/competitions/search?name=world%20cup" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 3, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "def get_competitions(query):\n", 61 | " url = \"https://api.fifa.com/api/v1/competitions/search\"\n", 62 | " params = {\n", 63 | " \"name\": query\n", 64 | " }\n", 65 | " r = requests.get(url, params=params)\n", 66 | " data = r.json()['Results']\n", 67 | " return data" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 4, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "competitions = get_competitions(\"world cup\")" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 5, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "{'IdCompetition': '17',\n", 88 | " 'Name': [{'Locale': 'en-GB', 'Description': 'FIFA World Cup™'}],\n", 89 | " 'IdConfederation': [],\n", 90 | " 'IdMemberAssociation': [],\n", 91 | " 'IdOwner': 'FIFA',\n", 92 | " 'Gender': 1,\n", 93 | " 'FootballType': 0,\n", 94 | " 'TeamType': 1,\n", 95 | " 'CompetitionType': 3,\n", 96 | " 'Properties': {'IdCBS': '17', 'IdIFES': 'FWC'},\n", 97 | " 'IsUpdateable': None}" 98 | ] 99 | }, 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "competitions[0]" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "world_cup_id = competitions[0]['IdCompetition']" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "## Get list of all world cup seasons\n", 123 | "\n", 124 | "https://api.fifa.com/api/v1/seasons?idCompetition=17" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 7, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "def get_seasons(competition_id):\n", 134 | " url = \"https://api.fifa.com/api/v1/seasons\"\n", 135 | " params = {\n", 136 | " \"idCompetition\": competition_id\n", 137 | " }\n", 138 | " r = requests.get(url, params=params)\n", 139 | " data = r.json()['Results']\n", 140 | " return data" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 8, 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "seasons = get_seasons(world_cup_id)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 9, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "22" 161 | ] 162 | }, 163 | "execution_count": 9, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "len(seasons)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 10, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "season_id = seasons[1]['IdSeason']" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "metadata": {}, 184 | "source": [ 185 | "## Get stages\n", 186 | "\n", 187 | "https://api.fifa.com/api/v1/stages?idCompetition=17&idSeason=254645" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 11, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "def get_stages(season_id, competition_id):\n", 197 | " url = \"https://api.fifa.com/api/v1/stages\"\n", 198 | " params = {\n", 199 | " \"idCompetition\": competition_id,\n", 200 | " \"idSeason\": season_id\n", 201 | " }\n", 202 | " r = requests.get(url, params=params)\n", 203 | " return r.json()['Results']" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 12, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "stages = get_stages(season_id, world_cup_id)" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 13, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "stages_map = {stage['IdStage']: stage['Name'][0]['Description'] for stage in stages}" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "## Get list of all world cup matches in a season\n", 229 | "\n", 230 | "https://api.fifa.com/api/v1/calendar/matches?idseason=254645&idcompetition=17" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 14, 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [ 239 | "def get_matches(competition_id, season_id):\n", 240 | " url = \"https://api.fifa.com/api/v1/calendar/matches\"\n", 241 | " params = {\n", 242 | " \"idcompetition\": competition_id,\n", 243 | " \"idseason\": season_id,\n", 244 | " \"count\": 100\n", 245 | " }\n", 246 | " r = requests.get(url, params=params)\n", 247 | " data = r.json()['Results']\n", 248 | " return data" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 15, 254 | "metadata": {}, 255 | "outputs": [], 256 | "source": [ 257 | "world_cup_matches = get_matches(world_cup_id, season_id)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 16, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "data": { 267 | "text/plain": [ 268 | "64" 269 | ] 270 | }, 271 | "execution_count": 16, 272 | "metadata": {}, 273 | "output_type": "execute_result" 274 | } 275 | ], 276 | "source": [ 277 | "len(world_cup_matches)" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "## Generate CSV file for matches data" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 17, 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [ 293 | "direct_fields = ['IdMatch', 'Attendance', 'MatchDay', 'Date', 'HomeTeamScore', 'AwayTeamScore', 'HomeTeamPenaltyScore',\n", 294 | " 'AwayTeamPenaltyScore', 'IsHomeMatch', 'MatchStatus', 'ResultType']" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 18, 300 | "metadata": {}, 301 | "outputs": [], 302 | "source": [ 303 | "matches_data = []" 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": 19, 309 | "metadata": {}, 310 | "outputs": [], 311 | "source": [ 312 | "for match in world_cup_matches:\n", 313 | " match_data = {}\n", 314 | " \n", 315 | " # set direct fields\n", 316 | " for field in direct_fields:\n", 317 | " match_data[field] = match[field]\n", 318 | " \n", 319 | " # set indirect fields\n", 320 | " match_data['Stage'] = stages_map[match['IdStage']]\n", 321 | " match_data['HomeTeamName'] = match['Home']['TeamName'][0]['Description']\n", 322 | " match_data['AwayTeamName'] = match['Away']['TeamName'][0]['Description']\n", 323 | " match_data['HomeTeamTactics'] = match['Home']['Tactics']\n", 324 | " match_data['AwayTeamTactics'] = match['Away']['Tactics']\n", 325 | " match_data['StadiumName'] = match['Stadium']['Name'][0]['Description']\n", 326 | " \n", 327 | " # set weather details\n", 328 | " match_data['Temperature'] = match['Weather']['Temperature']\n", 329 | " match_data['Humidity'] = match['Weather']['Humidity']\n", 330 | " match_data['WindSpeed'] = match['Weather']['WindSpeed']\n", 331 | " match_data['WeatherType'] = match['Weather']['TypeLocalized'][0]['Description']\n", 332 | " \n", 333 | " # set ball possession\n", 334 | " match_data['BallPossessionHome'] = match['BallPossession']['OverallHome']\n", 335 | " match_data['BallPossessionAway'] = match['BallPossession']['OverallAway']\n", 336 | " \n", 337 | " # set winner team name\n", 338 | " if match['Home']['IdTeam'] == match['Winner']:\n", 339 | " match_data['Winner'] = match_data['HomeTeamName']\n", 340 | " elif match['Away']['IdTeam'] == match['Winner']:\n", 341 | " match_data['Winner'] = match_data['AwayTeamName']\n", 342 | " else:\n", 343 | " match_data['Winner'] = None\n", 344 | " \n", 345 | " matches_data.append(match_data)" 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "execution_count": 20, 351 | "metadata": {}, 352 | "outputs": [], 353 | "source": [ 354 | "matches_data_headers = ['IdMatch', 'HomeTeamName', 'AwayTeamName', 'Attendance', 'MatchDay', 'Date', 'Stage', \n", 355 | " 'HomeTeamTactics', 'AwayTeamTactics', 'HomeTeamScore', 'AwayTeamScore', \n", 356 | " 'HomeTeamPenaltyScore', 'AwayTeamPenaltyScore', 'IsHomeMatch', 'MatchStatus', \n", 357 | " 'ResultType', 'StadiumName', 'Temperature', 'Humidity', 'WindSpeed', 'WeatherType', \n", 358 | " 'BallPossessionHome', 'BallPossessionAway', 'Winner']\n", 359 | "write_to_csv(matches_data, \"matches.csv\", matches_data_headers)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "## Get match details\n", 367 | "\n", 368 | "https://api.fifa.com/api/v1/live/football/17/254645/275093/300331537" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 21, 374 | "metadata": {}, 375 | "outputs": [], 376 | "source": [ 377 | "def get_match_detail(match_id, stage_id, season_id, competition_id):\n", 378 | " url = \"https://api.fifa.com/api/v1/live/football/{}/{}/{}/{}\".format(competition_id, season_id, stage_id, match_id)\n", 379 | " r = requests.get(url)\n", 380 | " data = r.json()\n", 381 | " return data" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": 22, 387 | "metadata": {}, 388 | "outputs": [], 389 | "source": [ 390 | "world_cup_matches_detailed = []" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 23, 396 | "metadata": { 397 | "scrolled": true 398 | }, 399 | "outputs": [ 400 | { 401 | "name": "stderr", 402 | "output_type": "stream", 403 | "text": [ 404 | "100%|██████████| 64/64 [01:17<00:00, 1.21s/it]\n" 405 | ] 406 | } 407 | ], 408 | "source": [ 409 | "for match in tqdm(world_cup_matches):\n", 410 | " data = get_match_detail(match['IdMatch'], match['IdStage'], match['IdSeason'], match['IdCompetition'])\n", 411 | " world_cup_matches_detailed.append(data)" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 24, 417 | "metadata": {}, 418 | "outputs": [ 419 | { 420 | "data": { 421 | "text/plain": [ 422 | "[{'Type': 1,\n", 423 | " 'IdPlayer': '201200',\n", 424 | " 'Minute': \"4'\",\n", 425 | " 'IdAssistPlayer': '269859',\n", 426 | " 'Period': 3,\n", 427 | " 'IdGoal': None,\n", 428 | " 'IdTeam': '43963'},\n", 429 | " {'Type': 2,\n", 430 | " 'IdPlayer': '201200',\n", 431 | " 'Minute': \"44'\",\n", 432 | " 'IdAssistPlayer': '269859',\n", 433 | " 'Period': 3,\n", 434 | " 'IdGoal': None,\n", 435 | " 'IdTeam': '43963'},\n", 436 | " {'Type': 2,\n", 437 | " 'IdPlayer': '201200',\n", 438 | " 'Minute': \"88'\",\n", 439 | " 'IdAssistPlayer': '269859',\n", 440 | " 'Period': 5,\n", 441 | " 'IdGoal': None,\n", 442 | " 'IdTeam': '43963'}]" 443 | ] 444 | }, 445 | "execution_count": 24, 446 | "metadata": {}, 447 | "output_type": "execute_result" 448 | } 449 | ], 450 | "source": [ 451 | "# Rememer this game?\n", 452 | "world_cup_matches_detailed[3]['HomeTeam']['Goals']" 453 | ] 454 | }, 455 | { 456 | "cell_type": "markdown", 457 | "metadata": {}, 458 | "source": [ 459 | "## Generate CSV file for goals data" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": 25, 465 | "metadata": {}, 466 | "outputs": [], 467 | "source": [ 468 | "goals_data = []" 469 | ] 470 | }, 471 | { 472 | "cell_type": "code", 473 | "execution_count": 26, 474 | "metadata": {}, 475 | "outputs": [], 476 | "source": [ 477 | "team_types = ['HomeTeam', 'AwayTeam']\n", 478 | "\n", 479 | "for match in world_cup_matches_detailed:\n", 480 | " match_id = match['IdMatch']\n", 481 | " player_map = {player['IdPlayer']: player for player in match['HomeTeam']['Players']+match['AwayTeam']['Players']}\n", 482 | " for idx, team in enumerate(team_types):\n", 483 | " team_name = match[team]['TeamName'][0]['Description']\n", 484 | " other_team_name = match[team_types[(idx+1)%2]]['TeamName'][0]['Description']\n", 485 | " for goal in match[team]['Goals']:\n", 486 | " goal_data = {}\n", 487 | " goal_data['IdMatch'] = match_id\n", 488 | " goal_data['Type'] = goal['Type']\n", 489 | " goal_data['Minute'] = goal['Minute']\n", 490 | " goal_data['TeamName'] = team_name\n", 491 | " goal_data['OppositionTeamName'] = other_team_name\n", 492 | " goal_data['PlayerName'] = player_map[goal['IdPlayer']]['PlayerName'][0]['Description']\n", 493 | " goal_data['Position'] = player_map[goal['IdPlayer']]['Position']\n", 494 | " goal_data['PlayerShirtNumber'] = player_map[goal['IdPlayer']]['ShirtNumber']\n", 495 | " goal_data['IsCaptain'] = player_map[goal['IdPlayer']]['Captain']\n", 496 | " if goal['IdAssistPlayer']:\n", 497 | " goal_data['GoalKeeperName'] = player_map[goal['IdAssistPlayer']]['PlayerName'][0]['Description']\n", 498 | " else:\n", 499 | " goal_data['GoalKeeperName'] = None\n", 500 | " goals_data.append(goal_data)" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 27, 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "data": { 510 | "text/plain": [ 511 | "169" 512 | ] 513 | }, 514 | "execution_count": 27, 515 | "metadata": {}, 516 | "output_type": "execute_result" 517 | } 518 | ], 519 | "source": [ 520 | "# number of proper goals\n", 521 | "len([goal['Minute'] for goal in goals_data if \"120\" not in goal['Minute']])" 522 | ] 523 | }, 524 | { 525 | "cell_type": "code", 526 | "execution_count": 28, 527 | "metadata": {}, 528 | "outputs": [], 529 | "source": [ 530 | "goals_data_headers = ['PlayerName', 'Minute', 'IdMatch', 'Type', 'TeamName', 'OppositionTeamName', 'Position', 'IsCaptain', 'GoalKeeperName', 'PlayerShirtNumber']\n", 531 | "write_to_csv(goals_data, \"goals.csv\", goals_data_headers)" 532 | ] 533 | }, 534 | { 535 | "cell_type": "markdown", 536 | "metadata": {}, 537 | "source": [ 538 | "## Get squads\n", 539 | "\n", 540 | "https://api.fifa.com/api/v1/teams/squads/all/17/254645?count=1000" 541 | ] 542 | }, 543 | { 544 | "cell_type": "code", 545 | "execution_count": 29, 546 | "metadata": {}, 547 | "outputs": [], 548 | "source": [ 549 | "def get_squads(competition_id, season_id):\n", 550 | " url = \"https://api.fifa.com/api/v1/teams/squads/all/{}/{}\".format(competition_id, season_id)\n", 551 | " params = {\n", 552 | " \"count\": 1000\n", 553 | " }\n", 554 | " r =requests.get(url)\n", 555 | " return r.json()['Results']" 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "execution_count": 30, 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [ 564 | "squads = get_squads(world_cup_id, season_id)" 565 | ] 566 | }, 567 | { 568 | "cell_type": "markdown", 569 | "metadata": {}, 570 | "source": [ 571 | "## Generate CSV for teams" 572 | ] 573 | }, 574 | { 575 | "cell_type": "code", 576 | "execution_count": 31, 577 | "metadata": {}, 578 | "outputs": [], 579 | "source": [ 580 | "def get_countries():\n", 581 | " url = \"https://api.fifa.com/api/v1/countries\"\n", 582 | " params = {\n", 583 | " \"count\": 1000\n", 584 | " }\n", 585 | " r = requests.get(url, params=params)\n", 586 | " return r.json()['Results']" 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": 32, 592 | "metadata": {}, 593 | "outputs": [], 594 | "source": [ 595 | "countries = get_countries()\n", 596 | "country_map = {country['IdCountry']: country['Name'] for country in countries}" 597 | ] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "execution_count": 33, 602 | "metadata": {}, 603 | "outputs": [], 604 | "source": [ 605 | "teams_data = []" 606 | ] 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": 34, 611 | "metadata": {}, 612 | "outputs": [], 613 | "source": [ 614 | "for squad in squads:\n", 615 | " team_data = {}\n", 616 | " team_data['IdTeam'] = squad['IdTeam']\n", 617 | " team_data['TeamName'] = squad['TeamName'][0]['Description']\n", 618 | " team_data['CoachName'] = squad['Officials'][0]['Name'][0]['Description']\n", 619 | " team_data['CoachCountry'] = country_map[squad['Officials'][0]['IdCountry']]\n", 620 | " teams_data.append(team_data)" 621 | ] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "execution_count": 35, 626 | "metadata": {}, 627 | "outputs": [], 628 | "source": [ 629 | "teams_data_headers = ['IdTeam', 'TeamName', 'CoachName', 'CoachCountry']\n", 630 | "write_to_csv(teams_data, \"teams.csv\", teams_data_headers)" 631 | ] 632 | }, 633 | { 634 | "cell_type": "markdown", 635 | "metadata": {}, 636 | "source": [ 637 | "## Get players data\n", 638 | "\n", 639 | "https://api.fifa.com/api/v1/players/201200" 640 | ] 641 | }, 642 | { 643 | "cell_type": "code", 644 | "execution_count": 36, 645 | "metadata": {}, 646 | "outputs": [], 647 | "source": [ 648 | "def get_player_data(player_id):\n", 649 | " url = \"https://api.fifa.com/api/v1/players/{}\".format(player_id)\n", 650 | " r = requests.get(url)\n", 651 | " data = r.json()\n", 652 | " player_data = {}\n", 653 | " player_data['Name'] = data['Name'][0]['Description']\n", 654 | " for field in ['IdPlayer', 'BirthDate', 'Weight', 'Height', 'InternationalCaps', 'Goals']:\n", 655 | " player_data[field] = data[field]\n", 656 | " return player_data" 657 | ] 658 | }, 659 | { 660 | "cell_type": "markdown", 661 | "metadata": {}, 662 | "source": [ 663 | "## Generate CSV file for players data" 664 | ] 665 | }, 666 | { 667 | "cell_type": "code", 668 | "execution_count": 37, 669 | "metadata": {}, 670 | "outputs": [], 671 | "source": [ 672 | "players_data = []" 673 | ] 674 | }, 675 | { 676 | "cell_type": "code", 677 | "execution_count": 38, 678 | "metadata": { 679 | "scrolled": false 680 | }, 681 | "outputs": [ 682 | { 683 | "name": "stderr", 684 | "output_type": "stream", 685 | "text": [ 686 | "Peru: 100%|██████████| 23/23 [00:28<00:00, 1.24s/it]\n", 687 | "Morocco: 100%|██████████| 23/23 [00:27<00:00, 1.21s/it]\n", 688 | "Egypt: 100%|██████████| 23/23 [00:25<00:00, 1.12s/it]\n", 689 | "IR Iran: 100%|██████████| 23/23 [00:29<00:00, 1.30s/it]\n", 690 | "Mexico: 100%|██████████| 23/23 [00:31<00:00, 1.36s/it]\n", 691 | "Saudi Arabia: 100%|██████████| 23/23 [00:40<00:00, 1.76s/it]\n", 692 | "Sweden: 100%|██████████| 23/23 [00:38<00:00, 1.68s/it]\n", 693 | "France: 100%|██████████| 23/23 [00:42<00:00, 1.86s/it]\n", 694 | "Senegal: 100%|██████████| 23/23 [00:44<00:00, 1.93s/it]\n", 695 | "Croatia: 100%|██████████| 23/23 [00:29<00:00, 1.30s/it]\n", 696 | "Poland: 100%|██████████| 23/23 [00:26<00:00, 1.16s/it]\n", 697 | "Brazil: 100%|██████████| 23/23 [00:23<00:00, 1.02s/it]\n", 698 | "Japan: 100%|██████████| 23/23 [00:22<00:00, 1.02it/s]\n", 699 | "Colombia: 100%|██████████| 23/23 [00:27<00:00, 1.20s/it]\n", 700 | "Spain: 100%|██████████| 23/23 [00:24<00:00, 1.08s/it]\n", 701 | "Switzerland: 100%|██████████| 23/23 [00:26<00:00, 1.14s/it]\n", 702 | "Denmark: 100%|██████████| 23/23 [00:27<00:00, 1.20s/it]\n", 703 | "Panama: 100%|██████████| 23/23 [00:27<00:00, 1.21s/it]\n", 704 | "Tunisia: 100%|██████████| 23/23 [00:27<00:00, 1.19s/it]\n", 705 | "Uruguay: 100%|██████████| 23/23 [00:27<00:00, 1.19s/it]\n", 706 | "Portugal: 100%|██████████| 23/23 [00:27<00:00, 1.18s/it]\n", 707 | "Australia: 100%|██████████| 23/23 [00:27<00:00, 1.18s/it]\n", 708 | "Germany: 100%|██████████| 23/23 [00:25<00:00, 1.12s/it]\n", 709 | "Costa Rica: 100%|██████████| 23/23 [00:30<00:00, 1.34s/it]\n", 710 | "Serbia: 100%|██████████| 23/23 [00:30<00:00, 1.34s/it]\n", 711 | "Iceland: 100%|██████████| 23/23 [00:36<00:00, 1.57s/it]\n", 712 | "England: 100%|██████████| 23/23 [00:27<00:00, 1.21s/it]\n", 713 | "Nigeria: 100%|██████████| 23/23 [00:26<00:00, 1.15s/it]\n", 714 | "Argentina: 100%|██████████| 23/23 [00:27<00:00, 1.20s/it]\n", 715 | "Korea Republic: 100%|██████████| 23/23 [00:28<00:00, 1.22s/it]\n", 716 | "Russia: 100%|██████████| 23/23 [00:26<00:00, 1.16s/it]\n", 717 | "Belgium: 100%|██████████| 23/23 [00:27<00:00, 1.17s/it]\n" 718 | ] 719 | } 720 | ], 721 | "source": [ 722 | "for squad in squads:\n", 723 | " team = squad['TeamName'][0]['Description']\n", 724 | " for player in tqdm(squad['Players'], desc=team):\n", 725 | " player_data = get_player_data(player['IdPlayer'])\n", 726 | " player_data['TeamName'] = team\n", 727 | " player_data['Position'] = player['PositionLocalized'][0]['Description']\n", 728 | " players_data.append(player_data)" 729 | ] 730 | }, 731 | { 732 | "cell_type": "code", 733 | "execution_count": 39, 734 | "metadata": {}, 735 | "outputs": [], 736 | "source": [ 737 | "players_data_headers = ['IdPlayer', 'Name', 'TeamName', 'Position', 'BirthDate', 'Weight', 'Height', 'InternationalCaps', 'Goals']\n", 738 | "write_to_csv(players_data, \"players.csv\", players_data_headers)" 739 | ] 740 | } 741 | ], 742 | "metadata": { 743 | "kernelspec": { 744 | "display_name": "Python 3", 745 | "language": "python", 746 | "name": "python3" 747 | }, 748 | "language_info": { 749 | "codemirror_mode": { 750 | "name": "ipython", 751 | "version": 3 752 | }, 753 | "file_extension": ".py", 754 | "mimetype": "text/x-python", 755 | "name": "python", 756 | "nbconvert_exporter": "python", 757 | "pygments_lexer": "ipython3", 758 | "version": "3.6.5" 759 | } 760 | }, 761 | "nbformat": 4, 762 | "nbformat_minor": 2 763 | } 764 | -------------------------------------------------------------------------------- /3.FIFAWC18Analysis/DataAnalysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![](https://i.imgur.com/A3Cxp7P.png)\n", 8 | "\n", 9 | "----\n", 10 | "\n", 11 | "- [Some analysis of Goals...](#Some-analysis-of-Goals...)\n", 12 | " - [Goals scored vs conceded per team](#Goals-scored-vs-conceded-per-team)\n", 13 | " - [Goal period](#Goal-period)\n", 14 | " - [Shirt number matters...](#Shirt-number-matters...)\n", 15 | " \n", 16 | " \n", 17 | "- [Some team analysis...](#Some-team-analysis...)\n", 18 | " - [What was the best stage native/foreign coaches were able to take their team to?](#What-was-the-best-stage-native/foreign-coaches-were-able-to-take-their-team-to?)\n", 19 | " \n", 20 | " \n", 21 | "- [Some analysis on players...](#Some-analysis-on-players...)\n", 22 | " - [Goalkeepers are biggg!!!](#Goalkeepers-are-biggg!!!)\n", 23 | " - [Some age analysis](#Some-age-analysis)\n", 24 | " - [None of the teams with average age above 28 could make it past Quarterfinals...](#None-of-the-teams-with-average-age-above-28-could-make-it-past-Quarterfinals...)\n", 25 | " \n", 26 | " \n", 27 | "- [Some match attendance analysis...](#Some-match-attendance-analysis...)\n", 28 | " - [Why so low attendance in quarters? Maybe bcoz of no Portugal, Spain and Argentina!](#Why-so-low-attendance-in-quarters?-Maybe-bcoz-of-no-Portugal,-Spain-and-Argentina!)\n", 29 | " \n", 30 | " \n", 31 | "- [Some analysis on team tactics...](#Some-analysis-on-team-tactics...)\n", 32 | " - [4-2-3-1 seems to be everyone's favorite. Does it guarantee a win?](#4-2-3-1-seems-to-be-everyone's-favorite.-Does-it-guarantee-a-win?)\n", 33 | " - [How does 4-2-3-1 tactic fares at big stage?](#How-does-4-2-3-1-tactic-fares-at-big-stage?)\n", 34 | " \n", 35 | " \n", 36 | "- [Some analysis on ball possession...](#Some-analysis-on-ball-possession...)\n", 37 | " - [In 4/6 matches, France had lesser ball possession than the opponent..](#In-4/6-matches,-France-had-lesser-ball-possession-than-the-opponent..)\n", 38 | " \n", 39 | "----" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": null, 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "import pandas as pd\n", 49 | "%matplotlib inline" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "teams_df = pd.read_csv(\"data/teams.csv\", index_col=\"IdTeam\")" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "teams_df.head()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "players_df = pd.read_csv(\"data/players.csv\", parse_dates=['BirthDate'], index_col=\"IdPlayer\")" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "players_df.head()" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "matches_df = pd.read_csv(\"data/matches.csv\", parse_dates=['Date'], index_col=\"IdMatch\")" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [ 103 | "matches_df.head()" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "goals_df = pd.read_csv(\"data/goals.csv\")" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": null, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "goals_df.head()" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "## Some analysis of Goals...\n", 129 | "![](https://i.imgflip.com/219r12.jpg)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "### Goals scored vs conceded per team" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "goals_scored_per_team = goals_df['TeamName'].value_counts()" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "goals_conceded_per_team = goals_df['OppositionTeamName'].value_counts()" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "goals_scored_per_team.get('Croatia')" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "teams_df['GoalsScored'] = teams_df['TeamName'].apply(goals_scored_per_team.get)" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "teams_df['GoalsConceded'] = teams_df['TeamName'].apply(goals_conceded_per_team.get)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "metadata": { 188 | "scrolled": false 189 | }, 190 | "outputs": [], 191 | "source": [ 192 | "# goals scored vs conceded\n", 193 | "teams_df.plot.bar(x='TeamName', y=['GoalsScored', 'GoalsConceded'], figsize=(15,6))" 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": null, 199 | "metadata": { 200 | "scrolled": false 201 | }, 202 | "outputs": [], 203 | "source": [ 204 | "# Which teams conceded more goals than they scored?\n", 205 | "teams_df.query('GoalsScored < GoalsConceded')" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": {}, 211 | "source": [ 212 | "### Goal period" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "def set_goal_period(minute):\n", 222 | " total = eval(minute.replace('\\'', ''))\n", 223 | " if \"45'+\" in minute or total<=45:\n", 224 | " return \"FirstHalf\"\n", 225 | " elif \"90'+\" in minute or 45