sportowe_wizualizacja/BarcaGoalLocByManagers.ipynb

362 lines
87 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#change this cell to change season and player name\n",
"season = ['2017/2018','2018/2019','2019/2020']\n",
"ssn = '0506'\n",
"length = int(20)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done\n"
]
}
],
"source": [
"import os\n",
"import json\n",
"import StatsbombPitch as sb\n",
"#from pandas.io.json import json_normalize\n",
"import codecs\n",
"import seaborn as sns\n",
"import pandas as pd\n",
"import codecs\n",
"import StatsbombPitch as sb\n",
"\n",
"main_df = pd.DataFrame(data=None)\n",
"path_match = \"/home/kirugulige/Documents/Football-Analytics/open-data-master/data/events/\" #location for play by play events\n",
"for root, dirs, files in os.walk('/home/kirugulige/Documents/Football-Analytics/open-data-master/data/matches'):\n",
" for file in files:\n",
" with open(os.path.join(root, file), \"r\") as auto:\n",
" with codecs.open(root + str('/') + file,encoding='utf-8') as data_file:\n",
" data = json.load(data_file)\n",
" df = pd.DataFrame(data=None)\n",
" df = pd.json_normalize(data, sep = \"_\")\n",
" #for x in df.competition_country_name:\n",
" # if x == 'Spain':\n",
" # print(df.match_id)\n",
" for i in range(len(df)):\n",
" if df.iloc[i]['competition_country_name'] == 'Spain' and df.iloc[i]['season_season_name'] in season :\n",
" match_no = df.iloc[i]['match_id'] #gets match with Spain as country\n",
" match_no = str(match_no) # from int to str \n",
" #print('match list \\n',match_no)\n",
" with codecs.open(path_match + match_no + str(r'.json'),encoding=\"utf8\") as event_file: #open the respective file\n",
" df_match = json.load(event_file)\n",
" df_match2 = pd.DataFrame(data=None)\n",
" df_match2 = pd.json_normalize(df_match,sep=\"_\") \n",
" df_match2 = df_match2[(df_match2['type_name'] == \"Shot\") & (df_match2['team_name'] == 'Barcelona')]\n",
" main_df = main_df.append(df_match2,ignore_index=True,sort=False) \n",
"#print('total matches ',len(match_no)) \n",
"print('Done')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#main_df['player_name'].value_counts()\n",
"df = main_df.loc[:,['location','shot_body_part_id','shot_end_location','shot_outcome_id','player_name','player_id']]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df['player_name'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df['shot_outcome_id'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>location</th>\n",
" <th>shot_body_part_id</th>\n",
" <th>shot_end_location</th>\n",
" <th>shot_outcome_id</th>\n",
" <th>player_name</th>\n",
" <th>player_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>[99.1, 44.1]</td>\n",
" <td>38.0</td>\n",
" <td>[120.0, 36.6, 2.2]</td>\n",
" <td>97.0</td>\n",
" <td>Lionel Andrés Messi Cuccittini</td>\n",
" <td>5503.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>[94.7, 51.6]</td>\n",
" <td>38.0</td>\n",
" <td>[120.0, 42.4, 0.4]</td>\n",
" <td>97.0</td>\n",
" <td>Lionel Andrés Messi Cuccittini</td>\n",
" <td>5503.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49</th>\n",
" <td>[106.7, 36.8]</td>\n",
" <td>38.0</td>\n",
" <td>[120.0, 37.9, 0.1]</td>\n",
" <td>97.0</td>\n",
" <td>Lionel Andrés Messi Cuccittini</td>\n",
" <td>5503.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>[114.1, 41.1]</td>\n",
" <td>38.0</td>\n",
" <td>[120.0, 39.0, 1.8]</td>\n",
" <td>97.0</td>\n",
" <td>Lionel Andrés Messi Cuccittini</td>\n",
" <td>5503.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
" <td>[109.3, 32.0]</td>\n",
" <td>38.0</td>\n",
" <td>[120.0, 40.9, 0.2]</td>\n",
" <td>97.0</td>\n",
" <td>Lionel Andrés Messi Cuccittini</td>\n",
" <td>5503.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" location shot_body_part_id shot_end_location shot_outcome_id \\\n",
"3 [99.1, 44.1] 38.0 [120.0, 36.6, 2.2] 97.0 \n",
"48 [94.7, 51.6] 38.0 [120.0, 42.4, 0.4] 97.0 \n",
"49 [106.7, 36.8] 38.0 [120.0, 37.9, 0.1] 97.0 \n",
"54 [114.1, 41.1] 38.0 [120.0, 39.0, 1.8] 97.0 \n",
"62 [109.3, 32.0] 38.0 [120.0, 40.9, 0.2] 97.0 \n",
"\n",
" player_name player_id \n",
"3 Lionel Andrés Messi Cuccittini 5503.0 \n",
"48 Lionel Andrés Messi Cuccittini 5503.0 \n",
"49 Lionel Andrés Messi Cuccittini 5503.0 \n",
"54 Lionel Andrés Messi Cuccittini 5503.0 \n",
"62 Lionel Andrés Messi Cuccittini 5503.0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#df_goal = df[(df['shot_outcome_id'] == 97) ]\n",
"#df_shot = df[(df['shot_outcome_id'] != 97) ]\n",
"\n",
"df_goal = df[(df['shot_outcome_id'] == 97) & (df['player_id'] == 5503.0)] #for messi\n",
"df_shot = df[(df['shot_outcome_id'] != 97) & (df['player_id'] == 5503.0)] #for messi\n",
"df_goal.head()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmsAAAGRCAYAAAA6rfQGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzs3XlgXGW5+PHvOWfWZLInbSgtbaBQaMG2QEW0IgV/UgUbqsBtyyarinAVFURFUXFh8comxf2yaFu4soQdF6jYKqVAW1rKbtKVNHsyk8xy5pz398d00kkyk0ySSWaSPJ9/lOnknHdOCHn6vs+iKaUQQgghhBC5Sc/2AoQQQgghRGoSrAkhhBBC5DAJ1oQQQgghcpgEa0IIIYQQOUyCNSGEEEKIHCbBmhBCCCFEDnOM5s2mrHDVA5NH855CCCGEELlk76qINpj3j/bOmgRqQgghhBCDIMegQgghhBA5TII1IYQQQogcNqo5a70tX7ic6gXV2VyCEGICmVExA4C6xrqsrkMIMXHUbKxh9brVw7pGVoO16gXVzJ46m+27t2dzGUKICSLPnZftJQghetDJc0zC0NzZXsiIyHO7qF6wdGwHawDbd29n2W3Lsr0MIcQEsObqNQDy3xwhcsQPPv8Ljj3yIDQPaIOqj8x9SkGep4C80KRhX0ty1oQQQgiRFdMrDsPhcYy7QA1iwWdRUWFGdg0lWBNCCCFEVuiaNi4DtTgtQx9OgjUhhBBCiGG4545fc99vHxix60uwJoQQQgiRw7JeYCCEEEIIkS2/uet3PFXzNCWlJVQeNJmjjj6KEz72YX7yvZ8RCoaYeshUfnjz9yksKuThNY/y8JpHiZom06ZP5cf/cyNer2fE1yg7a0IIIYQYE56peYazP34Gx85cwNkfP4Nnap4Z1vW2vf4Gf3vueR56ajV3/+FO3tj6JgDf++YNfPXaq/i/p9dw+KyZ/OrO3wJw6mmLWPXY/Tz01GqqDqvis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TQgghRNZFO91ozkk9XtOck4h2urO0otwhwZoQQgghss6RH0aZDT1eU2YDjvxwllaUOyRYE0IIIUTWeasasc0a7Eg9StnYkXpsswZvVWO2l5Z1UmAghBBCiKxzlesUHLOZYO2e7mrQ/COlGhQkWBNCCCFEjnCV67jKmxNekUAN5CkIIYQQQuQ0CdaEEEIIIXKYBGtCCCGEEDlMgjUhhBBCiBwmwZoQQgghRA6TalAhhBBijJLB5xODBGtCCCHEGCSDzycO+W4KIYQQY5AMPp84JFgTQgghxiAZfD5xSLAmhBBCjEEy+HzikGBNCCGEGINk8PnEIQUGQgghRI5LVfUpg88nBgnWhBBCiBw2UNWnDD4f/+S7KoQQQuQwqfoUWd1Zm1Exgzx3HmuuXpPNZYw7NRtrWL1udbaXIYQQIgOinW4M78hXfS5fuJzqBdUZveZEN3vqbLrCXcO+juysjTOzp86WHzYhhBhHRqvqs3pBNbOnzs7oNUVmZHVnra6xDoBlty3L5jLGFdmlFEKI8cVb1Yh/aw1QjeachDIbsLpqULZJ89opGR0ztX33dvmdnEGZ+p0sBQZCCCFEDutd9akZIWxVgqF/Fd0tY6YmAgnWhBBCiByXWPXZvrEMTVuB7qoEQHNVAtUEa/f0qgwV44WE4EIIIcQYImOmJh7ZWRNCCCHGEEd+GDvcsH9HLWYsjplK1ehX9CXBmhBCCDEGxIMbs9WF1fUgRsFCHL75KLMB26wh/8hGxsqB2UCNfkVPEqwJIYQQOS4xuHEUTQJjH1bgWWyrBncJY27MVGKjX5C8u4GMne+sEEIIMUH1nmLgLDgIV9mncZdA0YLmMRWogeTdDdbY+u4KIYQQE9B4C25Gq9HveCHBmhBCCJH
"text/plain": [
"<Figure size 748.8x489.6 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import StatsbombPitch as sb\n",
"sb.sb_pitch(\"#195905\",\"#faf0e6\",\"horizontal\",\"full\")\n",
"\n",
"for i in range(len(df_goal)):\n",
" xe = df_goal.iloc[i]['location'][0]\n",
" ye = df_goal.iloc[i]['location'][1]\n",
" g = plt.scatter(xe,ye,color=\"red\",edgecolors=\"black\",zorder=10,alpha=1)\n",
"for i in range(len(df_shot)):\n",
" xe = df_shot.iloc[i]['location'][0]\n",
" ye = df_shot.iloc[i]['location'][1]\n",
" s = plt.scatter(xe,ye,color=\"blue\",edgecolors=\"black\",zorder=5,alpha=0.6) \n",
"plt.legend((g,s),('goal','shot'),scatterpoints=1,loc=0) \n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmwAAAGhCAYAAADcC+jSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzsvXuc3HV97//8fL9z3Z3ZS3Y3CeGSLEYCgQhUAmpRQWrFKq5oi26qxaPHeqTUqrXtoefxa+05Kvanp6DHE20tWkWzQNW4WC9Vq5TGSwCJMZQQCezmypK9ZXdm5/ad7/dz/piZzczs3C87s5v38/HgETKXz/fz+Xxn8nnN+6q01giCIAiCIAjti9HqCQiCIAiCIAilEcEmCIIgCILQ5ohgEwRBEARBaHNEsAmCIAiCILQ5ItgEQRAEQRDaHBFsgiAIgiAIbY4INkEQWopS6i+VUv9Y5LmXK6UOLfec0tf+J6XUR5bpWh9WSn1lOa4lCMLKRASbIAgAKKXGlVIJpVR/3uP7lFJaKbWpGdfVWn9Ma/1fizz3H1rrLdWOqZR6iVJqQSkVKPDcPqXU7bXMVRAEoVWIYBMEIZsxYDjzF6XUNqCjddOpDa31z4HjwO9mP66UugzYCoy0Yl4qRcv+3VVKuVp1bUEQ6kMEmyAI2dwL/EHW328Fvpz9AqWUVyn1SaXUUaXU80qpzyml/Onn+pVS/6KUOq2UmlFK/UdGoCil/kIpd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QhBqRQSbINRIuwU9e6YWGNF2jlgaIcEbnMeI8Nco70XgaGAAzXtQvoOEDjzYUIEpCQyVUY9lthVWTG3B3KN9bWFJzmYlJksIQq3Ip1sQaqTdgp7Djl1QLC2
"text/plain": [
"<Figure size 748.8x489.6 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import StatsbombPitch as sb\n",
"sb.sb_pitch(\"#195905\",\"#faf0e6\",\"vertical\",\"half\")\n",
"\n",
"for i in range(len(df_goal)):\n",
" xe = df_goal.iloc[i]['location'][0]\n",
" ye = df_goal.iloc[i]['location'][1]\n",
" g = plt.scatter(ye,xe,color=\"red\",edgecolors=\"black\",zorder=10,alpha=1)\n",
"for i in range(len(df_shot)):\n",
" xe = df_shot.iloc[i]['location'][0]\n",
" ye = df_shot.iloc[i]['location'][1]\n",
" s = plt.scatter(ye,xe,color=\"blue\",edgecolors=\"black\",zorder=5,alpha=0.6) \n",
"plt.title('Messi in Valverde era') \n",
"\n",
"#ax = plt.subplot()\n",
"plt.legend((g,s),('goal','shot'),scatterpoints=1,loc=0)\n",
"plt.savefig('MessiValverdeEraScatter.png')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#type(df_goal.iloc[0]['location'])\n",
"dfj = pd.DataFrame(df_goal['location'].values.tolist(), columns=['x','y'])\n",
"dfj.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"hmap = dfj.to_numpy()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hdraw_pitch(\"#195905\",\"#faf0e6\",\"vertical\",\"half\")\n",
"#plt.gca().invert_xaxis()\n",
"sns.kdeplot(dfj.y,dfj.x, cmap=\"YlOrRd\", shade=True,shade_lowest = False,zorder = 20)\n",
"plt.title('Barca Valverde era') \n",
"plt.show()\n",
"\n",
"#plt.savefig('BarcaEnriqueeraheatmap.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import seaborn as sns\n",
"fig=plt.figure() #set up the figures\n",
"fig.set_size_inches(12, 8)\n",
"ax=fig.add_subplot(1,1,1)\n",
"\n",
"ax.set_facecolor('grey')\n",
"draw_pitch(ax) #overlay our different objects on the pitch\n",
"plt.ylim(-2, 82)\n",
"plt.xlim(-2, 122)\n",
"plt.axis('off')\n",
"plt.gca().invert_yaxis()\n",
"sns.kdeplot(dfj.x,dfj.y, cmap=\"YlOrRd\", shade=True,shade_lowest = False,n_levels=40)\n",
"#plt.hexbin(dfj.x, dfj.y,gridsize=(100,100))\n",
"#sns.jointplot(x=dfj['x'], y=dfj['y'], kind=\"kde\", space=0, color=\"r\",dropna='True');\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}