{ "cells": [ { "cell_type": "markdown", "id": "b22c6ee8", "metadata": {}, "source": [ "player_match_dataset_creation code for past seasons\n", "\n", "Select the season in season variable, and repeat the code if needed" ] }, { "cell_type": "code", "execution_count": 1, "id": "8a74364d", "metadata": {}, "outputs": [], "source": [ "season = '2021'" ] }, { "cell_type": "code", "execution_count": 2, "id": "8a6867a5", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_5084\\813865162.py:21: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " team_data['team_idx'][i] = team_data['team_idx'][i].split(' ')[-1]\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
teamteam_players_usedteam_possessionteam_gamesteam_games_startsteam_minutesteam_goalsteam_assiststeam_pens_madeteam_pens_att...vs_team_foulsvs_team_fouledvs_team_offsidesvs_team_pens_wonvs_team_pens_concededvs_team_own_goalsvs_team_ball_recoveriesvs_team_aerials_wonvs_team_aerials_lostvs_team_aerials_won_pct
team_idx
AtalantaAtalanta32.055.038.0418.03420.062.048.05.06.0...491.0488.069.04.06.03.02240.0518.0685.043.1
BolognaBologna36.050.638.0418.03420.043.034.04.05.0...527.0416.088.08.05.01.02032.0520.0492.051.4
CagliariCagliari33.044.538.0418.03420.034.026.03.04.0...526.0524.076.06.04.00.02112.0742.0696.051.6
EmpoliEmpoli28.047.438.0418.03420.047.027.07.07.0...488.0482.066.07.07.03.02051.0549.0427.056.3
FiorentinaFiorentina28.057.738.0418.03420.059.033.09.012.0...585.0441.0119.04.012.00.01825.0456.0469.049.3
GenoaGenoa40.043.938.0418.03420.026.019.06.07.0...523.0530.059.04.07.01.02257.0743.0635.053.9
VeronaHellas Verona31.050.638.0418.03420.063.044.07.08.0...463.0534.032.03.08.02.02206.0733.0689.051.5
InterInter27.056.538.0418.03420.083.057.07.011.0...440.0441.034.03.011.01.01767.0476.0549.046.4
JuventusJuventus32.051.538.0418.03420.056.037.05.06.0...525.0471.035.05.06.01.01894.0440.0550.044.4
LazioLazio27.055.438.0418.03420.074.048.07.09.0...474.0418.073.06.09.03.01956.0427.0411.051.0
MilanMilan28.054.038.0418.03420.066.039.05.08.0...533.0440.063.03.08.03.02106.0517.0521.049.8
NapoliNapoli27.058.338.0418.03420.074.046.010.014.0...517.0415.060.00.014.00.01963.0403.0393.050.6
RomaRoma29.051.438.0418.03420.058.031.07.09.0...497.0477.081.05.09.01.01970.0441.0524.045.7
SalernitanaSalernitana42.041.238.0418.03420.032.019.04.05.0...546.0463.063.06.05.01.02043.0506.0657.043.5
SampdoriaSampdoria34.046.138.0418.03420.042.029.02.04.0...538.0471.064.01.04.04.02174.0506.0609.045.4
SassuoloSassuolo29.054.938.0418.03420.060.039.07.07.0...519.0434.0142.06.07.04.02041.0404.0343.054.1
SpeziaSpezia30.042.738.0418.03420.038.025.03.05.0...474.0477.062.08.05.03.02064.0589.0530.052.6
TorinoTorino31.053.338.0418.03420.043.027.06.06.0...485.0611.060.010.06.03.01989.0891.0781.053.3
UdineseUdinese29.042.738.0418.03420.058.036.03.04.0...494.0537.057.06.04.03.02010.0534.0453.054.1
VeneziaVenezia39.042.338.0418.03420.034.023.03.05.0...476.0492.048.05.05.00.02059.0583.0564.050.8
\n", "

20 rows × 321 columns

\n", "
" ], "text/plain": [ " team team_players_used team_possession team_games \\\n", "team_idx \n", "Atalanta Atalanta 32.0 55.0 38.0 \n", "Bologna Bologna 36.0 50.6 38.0 \n", "Cagliari Cagliari 33.0 44.5 38.0 \n", "Empoli Empoli 28.0 47.4 38.0 \n", "Fiorentina Fiorentina 28.0 57.7 38.0 \n", "Genoa Genoa 40.0 43.9 38.0 \n", "Verona Hellas Verona 31.0 50.6 38.0 \n", "Inter Inter 27.0 56.5 38.0 \n", "Juventus Juventus 32.0 51.5 38.0 \n", "Lazio Lazio 27.0 55.4 38.0 \n", "Milan Milan 28.0 54.0 38.0 \n", "Napoli Napoli 27.0 58.3 38.0 \n", "Roma Roma 29.0 51.4 38.0 \n", "Salernitana Salernitana 42.0 41.2 38.0 \n", "Sampdoria Sampdoria 34.0 46.1 38.0 \n", "Sassuolo Sassuolo 29.0 54.9 38.0 \n", "Spezia Spezia 30.0 42.7 38.0 \n", "Torino Torino 31.0 53.3 38.0 \n", "Udinese Udinese 29.0 42.7 38.0 \n", "Venezia Venezia 39.0 42.3 38.0 \n", "\n", " team_games_starts team_minutes team_goals team_assists \\\n", "team_idx \n", "Atalanta 418.0 3420.0 62.0 48.0 \n", "Bologna 418.0 3420.0 43.0 34.0 \n", "Cagliari 418.0 3420.0 34.0 26.0 \n", "Empoli 418.0 3420.0 47.0 27.0 \n", "Fiorentina 418.0 3420.0 59.0 33.0 \n", "Genoa 418.0 3420.0 26.0 19.0 \n", "Verona 418.0 3420.0 63.0 44.0 \n", "Inter 418.0 3420.0 83.0 57.0 \n", "Juventus 418.0 3420.0 56.0 37.0 \n", "Lazio 418.0 3420.0 74.0 48.0 \n", "Milan 418.0 3420.0 66.0 39.0 \n", "Napoli 418.0 3420.0 74.0 46.0 \n", "Roma 418.0 3420.0 58.0 31.0 \n", "Salernitana 418.0 3420.0 32.0 19.0 \n", "Sampdoria 418.0 3420.0 42.0 29.0 \n", "Sassuolo 418.0 3420.0 60.0 39.0 \n", "Spezia 418.0 3420.0 38.0 25.0 \n", "Torino 418.0 3420.0 43.0 27.0 \n", "Udinese 418.0 3420.0 58.0 36.0 \n", "Venezia 418.0 3420.0 34.0 23.0 \n", "\n", " team_pens_made team_pens_att ... vs_team_fouls \\\n", "team_idx ... \n", "Atalanta 5.0 6.0 ... 491.0 \n", "Bologna 4.0 5.0 ... 527.0 \n", "Cagliari 3.0 4.0 ... 526.0 \n", "Empoli 7.0 7.0 ... 488.0 \n", "Fiorentina 9.0 12.0 ... 585.0 \n", "Genoa 6.0 7.0 ... 523.0 \n", "Verona 7.0 8.0 ... 463.0 \n", "Inter 7.0 11.0 ... 440.0 \n", "Juventus 5.0 6.0 ... 525.0 \n", "Lazio 7.0 9.0 ... 474.0 \n", "Milan 5.0 8.0 ... 533.0 \n", "Napoli 10.0 14.0 ... 517.0 \n", "Roma 7.0 9.0 ... 497.0 \n", "Salernitana 4.0 5.0 ... 546.0 \n", "Sampdoria 2.0 4.0 ... 538.0 \n", "Sassuolo 7.0 7.0 ... 519.0 \n", "Spezia 3.0 5.0 ... 474.0 \n", "Torino 6.0 6.0 ... 485.0 \n", "Udinese 3.0 4.0 ... 494.0 \n", "Venezia 3.0 5.0 ... 476.0 \n", "\n", " vs_team_fouled vs_team_offsides vs_team_pens_won \\\n", "team_idx \n", "Atalanta 488.0 69.0 4.0 \n", "Bologna 416.0 88.0 8.0 \n", "Cagliari 524.0 76.0 6.0 \n", "Empoli 482.0 66.0 7.0 \n", "Fiorentina 441.0 119.0 4.0 \n", "Genoa 530.0 59.0 4.0 \n", "Verona 534.0 32.0 3.0 \n", "Inter 441.0 34.0 3.0 \n", "Juventus 471.0 35.0 5.0 \n", "Lazio 418.0 73.0 6.0 \n", "Milan 440.0 63.0 3.0 \n", "Napoli 415.0 60.0 0.0 \n", "Roma 477.0 81.0 5.0 \n", "Salernitana 463.0 63.0 6.0 \n", "Sampdoria 471.0 64.0 1.0 \n", "Sassuolo 434.0 142.0 6.0 \n", "Spezia 477.0 62.0 8.0 \n", "Torino 611.0 60.0 10.0 \n", "Udinese 537.0 57.0 6.0 \n", "Venezia 492.0 48.0 5.0 \n", "\n", " vs_team_pens_conceded vs_team_own_goals \\\n", "team_idx \n", "Atalanta 6.0 3.0 \n", "Bologna 5.0 1.0 \n", "Cagliari 4.0 0.0 \n", "Empoli 7.0 3.0 \n", "Fiorentina 12.0 0.0 \n", "Genoa 7.0 1.0 \n", "Verona 8.0 2.0 \n", "Inter 11.0 1.0 \n", "Juventus 6.0 1.0 \n", "Lazio 9.0 3.0 \n", "Milan 8.0 3.0 \n", "Napoli 14.0 0.0 \n", "Roma 9.0 1.0 \n", "Salernitana 5.0 1.0 \n", "Sampdoria 4.0 4.0 \n", "Sassuolo 7.0 4.0 \n", "Spezia 5.0 3.0 \n", "Torino 6.0 3.0 \n", "Udinese 4.0 3.0 \n", "Venezia 5.0 0.0 \n", "\n", " vs_team_ball_recoveries vs_team_aerials_won \\\n", "team_idx \n", "Atalanta 2240.0 518.0 \n", "Bologna 2032.0 520.0 \n", "Cagliari 2112.0 742.0 \n", "Empoli 2051.0 549.0 \n", "Fiorentina 1825.0 456.0 \n", "Genoa 2257.0 743.0 \n", "Verona 2206.0 733.0 \n", "Inter 1767.0 476.0 \n", "Juventus 1894.0 440.0 \n", "Lazio 1956.0 427.0 \n", "Milan 2106.0 517.0 \n", "Napoli 1963.0 403.0 \n", "Roma 1970.0 441.0 \n", "Salernitana 2043.0 506.0 \n", "Sampdoria 2174.0 506.0 \n", "Sassuolo 2041.0 404.0 \n", "Spezia 2064.0 589.0 \n", "Torino 1989.0 891.0 \n", "Udinese 2010.0 534.0 \n", "Venezia 2059.0 583.0 \n", "\n", " vs_team_aerials_lost vs_team_aerials_won_pct \n", "team_idx \n", "Atalanta 685.0 43.1 \n", "Bologna 492.0 51.4 \n", "Cagliari 696.0 51.6 \n", "Empoli 427.0 56.3 \n", "Fiorentina 469.0 49.3 \n", "Genoa 635.0 53.9 \n", "Verona 689.0 51.5 \n", "Inter 549.0 46.4 \n", "Juventus 550.0 44.4 \n", "Lazio 411.0 51.0 \n", "Milan 521.0 49.8 \n", "Napoli 393.0 50.6 \n", "Roma 524.0 45.7 \n", "Salernitana 657.0 43.5 \n", "Sampdoria 609.0 45.4 \n", "Sassuolo 343.0 54.1 \n", "Spezia 530.0 52.6 \n", "Torino 781.0 53.3 \n", "Udinese 453.0 54.1 \n", "Venezia 564.0 50.8 \n", "\n", "[20 rows x 321 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "rcsv = pd.read_csv('fbref_data/season' + season + '/teams.csv') \n", "team = pd.DataFrame(rcsv)\n", "\n", "rcsv = pd.read_csv('fbref_data/season' + season + '/teams_vs.csv') \n", "vs_team = pd.DataFrame(rcsv)\n", "\n", "for i in range(1, team.shape[1]):\n", " team = team.rename(columns = {team.columns[i] : 'team_' + team.columns[i]})\n", " \n", "for i in range(1, vs_team.shape[1]):\n", " vs_team = vs_team.rename(columns = {vs_team.columns[i] : 'vs_team_' + vs_team.columns[i]})\n", " \n", "vs_team.pop('team')\n", "\n", "team_data = pd.concat([team, vs_team], axis = 1)\n", "\n", "team_data['team_idx'] = team_data['team']\n", "for i in range(team_data.shape[0]):\n", " team_data['team_idx'][i] = team_data['team_idx'][i].split(' ')[-1]\n", "\n", "team_data = team_data.set_index('team_idx')\n", "\n", "team_data\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "b6a3db98", "metadata": {}, "outputs": [], "source": [ "team_data.to_excel('mid_outputs/season' + season + '/team_data.xlsx')" ] }, { "cell_type": "code", "execution_count": 4, "id": "c34eb398", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0idrteamsurnameinitialfb_IDagebirth_yeargames...gk_pct_goal_kicks_launchedgk_goal_kick_length_avggk_crossesgk_crosses_stoppedgk_crosses_stopped_pctgk_def_actions_outside_pen_areagk_def_actions_outside_pen_area_per90gk_avg_distance_def_actionsvote_avgvote_std
name
Maignan04312PMilanMaignanNaN6472619950...38.936.5347.025.07.245.01.4116.86.2656250.483871
Szczesny1453PJuventusSzczesnyNaN6753119900...29.731.5481.024.05.025.00.7613.56.1212120.628012
Ospina22468PNapoliOspinaNaN6533219880...14.122.5353.018.05.131.01.0017.06.2580650.332899
Handanovic3250PInterHandanovicNaN6443719840...20.426.5393.015.03.810.00.2711.26.1621620.533399
Berisha4316PTorinoBerishaNaN6373219890...87.258.6148.07.04.710.01.0014.66.1000000.700000
..................................................................
Kokorin5455391AFiorentinaKokorinNaN2813019916...0.00.00.00.00.00.00.000.06.1067780.250641
Munteanu5465458AFiorentinaMunteanuNaN-1000...0.00.00.00.00.00.00.000.06.2844840.401907
Buksa5475459AGenoaBuksaNaN831820034...0.00.00.00.00.00.00.000.05.9425600.627453
Kaio Jorge5485505AJuventusJorgeNaN2641920029...0.00.00.00.00.00.00.000.05.9469360.380747
Lazetic5495785AMilanLazeticNaN-1000...0.00.00.00.00.00.00.000.06.1585300.318287
\n", "

550 rows × 169 columns

\n", "
" ], "text/plain": [ " Unnamed: 0 id r team surname initial fb_ID age \\\n", "name \n", "Maignan 0 4312 P Milan Maignan NaN 647 26 \n", "Szczesny 1 453 P Juventus Szczesny NaN 675 31 \n", "Ospina 2 2468 P Napoli Ospina NaN 653 32 \n", "Handanovic 3 250 P Inter Handanovic NaN 644 37 \n", "Berisha 4 316 P Torino Berisha NaN 637 32 \n", "... ... ... .. ... ... ... ... ... \n", "Kokorin 545 5391 A Fiorentina Kokorin NaN 281 30 \n", "Munteanu 546 5458 A Fiorentina Munteanu NaN -1 0 \n", "Buksa 547 5459 A Genoa Buksa NaN 83 18 \n", "Kaio Jorge 548 5505 A Juventus Jorge NaN 264 19 \n", "Lazetic 549 5785 A Milan Lazetic NaN -1 0 \n", "\n", " birth_year games ... gk_pct_goal_kicks_launched \\\n", "name ... \n", "Maignan 1995 0 ... 38.9 \n", "Szczesny 1990 0 ... 29.7 \n", "Ospina 1988 0 ... 14.1 \n", "Handanovic 1984 0 ... 20.4 \n", "Berisha 1989 0 ... 87.2 \n", "... ... ... ... ... \n", "Kokorin 1991 6 ... 0.0 \n", "Munteanu 0 0 ... 0.0 \n", "Buksa 2003 4 ... 0.0 \n", "Kaio Jorge 2002 9 ... 0.0 \n", "Lazetic 0 0 ... 0.0 \n", "\n", " gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n", "name \n", "Maignan 36.5 347.0 25.0 \n", "Szczesny 31.5 481.0 24.0 \n", "Ospina 22.5 353.0 18.0 \n", "Handanovic 26.5 393.0 15.0 \n", "Berisha 58.6 148.0 7.0 \n", "... ... ... ... \n", "Kokorin 0.0 0.0 0.0 \n", "Munteanu 0.0 0.0 0.0 \n", "Buksa 0.0 0.0 0.0 \n", "Kaio Jorge 0.0 0.0 0.0 \n", "Lazetic 0.0 0.0 0.0 \n", "\n", " gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n", "name \n", "Maignan 7.2 45.0 \n", "Szczesny 5.0 25.0 \n", "Ospina 5.1 31.0 \n", "Handanovic 3.8 10.0 \n", "Berisha 4.7 10.0 \n", "... ... ... \n", "Kokorin 0.0 0.0 \n", "Munteanu 0.0 0.0 \n", "Buksa 0.0 0.0 \n", "Kaio Jorge 0.0 0.0 \n", "Lazetic 0.0 0.0 \n", "\n", " gk_def_actions_outside_pen_area_per90 \\\n", "name \n", "Maignan 1.41 \n", "Szczesny 0.76 \n", "Ospina 1.00 \n", "Handanovic 0.27 \n", "Berisha 1.00 \n", "... ... \n", "Kokorin 0.00 \n", "Munteanu 0.00 \n", "Buksa 0.00 \n", "Kaio Jorge 0.00 \n", "Lazetic 0.00 \n", "\n", " gk_avg_distance_def_actions vote_avg vote_std \n", "name \n", "Maignan 16.8 6.265625 0.483871 \n", "Szczesny 13.5 6.121212 0.628012 \n", "Ospina 17.0 6.258065 0.332899 \n", "Handanovic 11.2 6.162162 0.533399 \n", "Berisha 14.6 6.100000 0.700000 \n", "... ... ... ... \n", "Kokorin 0.0 6.106778 0.250641 \n", "Munteanu 0.0 6.284484 0.401907 \n", "Buksa 0.0 5.942560 0.627453 \n", "Kaio Jorge 0.0 5.946936 0.380747 \n", "Lazetic 0.0 6.158530 0.318287 \n", "\n", "[550 rows x 169 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rx = pd.read_excel('mid_outputs/season' + season + '/players_stats.xlsx', index_col = 3) \n", "players = pd.DataFrame(rx)\n", "\n", "players\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "f9f7f88c", "metadata": {}, "outputs": [], "source": [ "def player_match_data(player, pteam, oppteam):\n", " if(not(player in players.index)):\n", " return None\n", " \n", " pdata = players.loc[[player]]\n", " \n", " pteam_stats = team_data.loc[[pteam]].rename(index = {pteam : player})\n", " \n", " oppteam_stats = team_data.loc[[oppteam]].rename(index = {oppteam : player})\n", " \n", " oppteam_stats = oppteam_stats.rename(lambda x: 'opp_' + x, axis='columns')\n", " \n", " out = pd.concat([pdata, pteam_stats, oppteam_stats], axis = 1)\n", " \n", " return(out)\n", " " ] }, { "cell_type": "code", "execution_count": 6, "id": "7eb4e666", "metadata": {}, "outputs": [ { "ename": "PermissionError", "evalue": "[Errno 13] Permission denied: 'tmp/playermatchdata.xlsx'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mPermissionError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_5084\\2433661448.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mtest\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mplayer_match_data\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Immobile'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Lazio'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Atalanta'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_excel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'tmp/playermatchdata.xlsx'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mtest\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36mto_excel\u001b[1;34m(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes, storage_options)\u001b[0m\n\u001b[0;32m 2343\u001b[0m \u001b[0minf_rep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minf_rep\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2344\u001b[0m )\n\u001b[1;32m-> 2345\u001b[1;33m formatter.write(\n\u001b[0m\u001b[0;32m 2346\u001b[0m \u001b[0mexcel_writer\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2347\u001b[0m \u001b[0msheet_name\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msheet_name\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\io\\formats\\excel.py\u001b[0m in \u001b[0;36mwrite\u001b[1;34m(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options)\u001b[0m\n\u001b[0;32m 886\u001b[0m \u001b[1;31m# error: Cannot instantiate abstract class 'ExcelWriter' with abstract\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 887\u001b[0m \u001b[1;31m# attributes 'engine', 'save', 'supported_extensions' and 'write_cells'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 888\u001b[1;33m writer = ExcelWriter( # type: ignore[abstract]\n\u001b[0m\u001b[0;32m 889\u001b[0m \u001b[0mwriter\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstorage_options\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstorage_options\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 890\u001b[0m )\n", "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\io\\excel\\_xlsxwriter.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs)\u001b[0m\n\u001b[0;32m 189\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Append mode is not supported with xlsxwriter!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 190\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 191\u001b[1;33m super().__init__(\n\u001b[0m\u001b[0;32m 192\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 193\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\io\\excel\\_base.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs)\u001b[0m\n\u001b[0;32m 1104\u001b[0m )\n\u001b[0;32m 1105\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mExcelWriter\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1106\u001b[1;33m self.handles = get_handle(\n\u001b[0m\u001b[0;32m 1107\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstorage_options\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstorage_options\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mis_text\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1108\u001b[0m )\n", "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pandas\\io\\common.py\u001b[0m in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m 793\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 794\u001b[0m \u001b[1;31m# Binary mode\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 795\u001b[1;33m \u001b[0mhandle\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mioargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 796\u001b[0m \u001b[0mhandles\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhandle\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 797\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mPermissionError\u001b[0m: [Errno 13] Permission denied: 'tmp/playermatchdata.xlsx'" ] } ], "source": [ "test = player_match_data('Immobile', 'Lazio', 'Atalanta')\n", "test.to_excel('tmp/playermatchdata.xlsx')\n", "\n", "test" ] }, { "cell_type": "code", "execution_count": null, "id": "6b4c1b00", "metadata": {}, "outputs": [], "source": [ "pteam = 'Lazio'\n", "pteam_stats = team_data.loc[[pteam]]\n", "pteam_stats.index[0]" ] }, { "cell_type": "code", "execution_count": 7, "id": "6ea6df1f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['r',\n", " 'fb_ID',\n", " 'games',\n", " 'games_starts',\n", " 'minutes',\n", " 'goals',\n", " 'assists',\n", " 'cards_yellow',\n", " 'cards_red',\n", " 'xg',\n", " 'npxg',\n", " 'shots_on_target',\n", " 'shots_on_target_pct',\n", " 'goals_per_shot',\n", " 'goals_per_shot_on_target',\n", " 'passes_completed',\n", " 'passes_pct',\n", " 'passes_into_final_third',\n", " 'passes_into_penalty_area',\n", " 'progressive_passes',\n", " 'passes_live',\n", " 'passes_dead',\n", " 'through_balls',\n", " 'passes_switches',\n", " 'crosses',\n", " 'corner_kicks',\n", " 'dribble_tackles',\n", " 'dribbles_vs',\n", " 'dribble_tackles_pct',\n", " 'dribbled_past',\n", " 'blocks',\n", " 'blocked_shots',\n", " 'blocked_passes',\n", " 'interceptions',\n", " 'clearances',\n", " 'errors',\n", " 'touches',\n", " 'touches_def_pen_area',\n", " 'touches_def_3rd',\n", " 'touches_mid_3rd',\n", " 'touches_att_3rd',\n", " 'touches_att_pen_area',\n", " 'touches_live_ball',\n", " 'dribbles_completed',\n", " 'dribbles',\n", " 'dribbles_completed_pct',\n", " 'carries',\n", " 'progressive_carries',\n", " 'carries_into_final_third',\n", " 'carries_into_penalty_area',\n", " 'passes_received',\n", " 'miscontrols',\n", " 'dispossessed',\n", " 'fouls',\n", " 'fouled',\n", " 'aerials_won',\n", " 'aerials_lost',\n", " 'aerials_won_pct',\n", " 'team_possession',\n", " 'team_goals_assists_per90',\n", " 'team_goals_pens_per90',\n", " 'team_goals_assists_pens_per90',\n", " 'team_xg_per90',\n", " 'team_gk_goals_against_per90',\n", " 'team_gk_save_pct',\n", " 'team_gk_clean_sheets_pct',\n", " 'team_passes_pct',\n", " 'team_passes_pct_medium',\n", " 'team_passes_pct_long',\n", " 'team_sca_per90',\n", " 'team_gca_per90',\n", " 'team_dribble_tackles_pct',\n", " 'team_aerials_won_pct',\n", " 'vs_team_possession',\n", " 'vs_team_goals_per90',\n", " 'vs_team_assists_per90',\n", " 'vs_team_xg_per90',\n", " 'vs_team_gk_save_pct',\n", " 'vs_team_gk_clean_sheets_pct',\n", " 'vs_team_gk_pct_passes_launched',\n", " 'vs_team_gk_crosses_stopped_pct',\n", " 'vs_team_shots_on_target_per90',\n", " 'vs_team_passes_pct',\n", " 'vs_team_passes_pct_short',\n", " 'vs_team_passes_pct_medium',\n", " 'vs_team_passes_pct_long',\n", " 'vs_team_sca_per90',\n", " 'vs_team_gca_per90',\n", " 'vs_team_dribble_tackles_pct',\n", " 'vs_team_dribbles_completed_pct',\n", " 'vs_team_aerials_won_pct']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rx = pd.read_excel('tmp/playermatchdata_sel.xlsx', index_col = 0, header = None) \n", "\n", "out = list()\n", "\n", "for i in range(1, rx.shape[1]):\n", " if(rx[i][2] == \"x\"):\n", " out.append(rx[i][0])\n", " \n", "out" ] }, { "cell_type": "code", "execution_count": 8, "id": "47bc651f", "metadata": {}, "outputs": [], "source": [ "features_abs = ['r',\n", " 'games',\n", " 'games_starts', \n", " 'minutes',\n", " 'shots_on_target_pct',\n", " 'goals_per_shot',\n", " 'goals_per_shot_on_target',\n", " 'passes_pct',\n", " 'dribble_tackles_pct',\n", " 'dribbles_completed_pct',\n", " 'aerials_won_pct',\n", " 'team_possession',\n", " 'team_goals_assists_per90',\n", " 'team_goals_pens_per90',\n", " 'team_goals_assists_pens_per90',\n", " 'team_xg_per90',\n", " 'team_gk_goals_against_per90',\n", " 'team_gk_save_pct',\n", " 'team_gk_clean_sheets_pct',\n", " 'team_passes_pct',\n", " 'team_passes_pct_medium',\n", " 'team_passes_pct_long',\n", " 'team_sca_per90',\n", " 'team_gca_per90',\n", " 'team_dribble_tackles_pct',\n", " 'team_aerials_won_pct',\n", " 'vs_team_possession',\n", " 'vs_team_goals_per90',\n", " 'vs_team_assists_per90',\n", " 'vs_team_xg_per90',\n", " 'vs_team_gk_save_pct',\n", " 'vs_team_gk_clean_sheets_pct',\n", " 'vs_team_gk_pct_passes_launched',\n", " 'vs_team_gk_crosses_stopped_pct',\n", " 'vs_team_shots_on_target_per90',\n", " 'vs_team_passes_pct',\n", " 'vs_team_passes_pct_short',\n", " 'vs_team_passes_pct_medium',\n", " 'vs_team_passes_pct_long',\n", " 'vs_team_sca_per90',\n", " 'vs_team_gca_per90',\n", " 'vs_team_dribble_tackles_pct',\n", " 'vs_team_dribbles_completed_pct',\n", " 'vs_team_aerials_won_pct',\n", " 'opp_team_possession',\n", " 'opp_team_goals_assists_per90',\n", " 'opp_team_goals_pens_per90',\n", " 'opp_team_goals_assists_pens_per90',\n", " 'opp_team_xg_per90',\n", " 'opp_team_gk_goals_against_per90',\n", " 'opp_team_gk_save_pct',\n", " 'opp_team_gk_clean_sheets_pct',\n", " 'opp_team_passes_pct',\n", " 'opp_team_passes_pct_medium',\n", " 'opp_team_passes_pct_long',\n", " 'opp_team_sca_per90',\n", " 'opp_team_gca_per90',\n", " 'opp_team_dribble_tackles_pct',\n", " 'opp_team_aerials_won_pct',\n", " 'opp_vs_team_possession',\n", " 'opp_vs_team_goals_per90',\n", " 'opp_vs_team_assists_per90',\n", " 'opp_vs_team_xg_per90',\n", " 'opp_vs_team_gk_save_pct',\n", " 'opp_vs_team_gk_clean_sheets_pct',\n", " 'opp_vs_team_gk_pct_passes_launched',\n", " 'opp_vs_team_gk_crosses_stopped_pct',\n", " 'opp_vs_team_shots_on_target_per90',\n", " 'opp_vs_team_passes_pct',\n", " 'opp_vs_team_passes_pct_short',\n", " 'opp_vs_team_passes_pct_medium',\n", " 'opp_vs_team_passes_pct_long',\n", " 'opp_vs_team_sca_per90',\n", " 'opp_vs_team_gca_per90',\n", " 'opp_vs_team_dribble_tackles_pct',\n", " 'opp_vs_team_dribbles_completed_pct',\n", " 'opp_vs_team_aerials_won_pct',\n", " \n", " 'vote_avg',\n", " 'vote_std']\n", "\n", "features_rel = [\n", " 'goals',\n", " 'assists',\n", " 'cards_yellow',\n", " 'cards_red',\n", " 'xg',\n", " 'npxg',\n", " 'shots_on_target',\n", " 'passes_completed',\n", " 'passes_into_final_third',\n", " 'passes_into_penalty_area',\n", " 'progressive_passes',\n", " 'passes_live',\n", " 'passes_dead',\n", " 'through_balls',\n", " 'passes_switches',\n", " 'crosses',\n", " 'corner_kicks',\n", " 'dribble_tackles',\n", " 'dribbles_vs',\n", " 'dribbled_past',\n", " 'blocks',\n", " 'blocked_shots',\n", " 'blocked_passes',\n", " 'interceptions',\n", " 'clearances',\n", " 'errors',\n", " 'touches',\n", " 'touches_def_pen_area',\n", " 'touches_def_3rd',\n", " 'touches_mid_3rd',\n", " 'touches_att_3rd',\n", " 'touches_att_pen_area',\n", " 'touches_live_ball',\n", " 'dribbles_completed',\n", " 'dribbles',\n", " 'passes_received',\n", " 'miscontrols',\n", " 'dispossessed',\n", " 'fouls',\n", " 'fouled',\n", " 'aerials_won',\n", " 'aerials_lost',\n", " 'carries',\n", " 'progressive_carries',\n", " 'carries_into_final_third',\n", " 'carries_into_penalty_area']\n", "\n", "features_rel_gamecorr = [\n", " 'goals',\n", " 'assists',\n", " 'xg',\n", " 'npxg',\n", " 'cards_yellow',\n", " 'cards_red'\n", "]" ] }, { "cell_type": "code", "execution_count": 9, "id": "3f43d509", "metadata": {}, "outputs": [], "source": [ "def player_match_data_ext(player, pteam, oppteam):\n", " pdata = player_match_data(player, pteam, oppteam)\n", " \n", " if(not isinstance(pdata, pd.DataFrame)):\n", " return None\n", " \n", " out = pd.concat([pdata[features_abs], pdata[features_rel]], axis = 1)\n", " \n", " out[features_rel] = out[features_rel] / max(pdata['minutes'][0], 1)\n", " \n", " out[features_rel_gamecorr] = out[features_rel_gamecorr] * (pdata['minutes'][0] / max(pdata['games'][0], 1) / 90)\n", " \n", " return out\n", " " ] }, { "cell_type": "code", "execution_count": 10, "id": "930d00c7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rgamesgames_startsminutesshots_on_target_pctgoals_per_shotgoals_per_shot_on_targetpasses_pctdribble_tackles_pctdribbles_completed_pct...miscontrolsdispossessedfoulsfouledaerials_wonaerials_lostcarriesprogressive_carriescarries_into_final_thirdcarries_into_penalty_area
ImmobileA3131271145.90.180.477.06.747.5...0.0284030.016230.0132790.0143860.0081150.0169680.2674290.0191810.0114350.011435
\n", "

1 rows × 125 columns

\n", "
" ], "text/plain": [ " r games games_starts minutes shots_on_target_pct \\\n", "Immobile A 31 31 2711 45.9 \n", "\n", " goals_per_shot goals_per_shot_on_target passes_pct \\\n", "Immobile 0.18 0.4 77.0 \n", "\n", " dribble_tackles_pct dribbles_completed_pct ... miscontrols \\\n", "Immobile 6.7 47.5 ... 0.028403 \n", "\n", " dispossessed fouls fouled aerials_won aerials_lost \\\n", "Immobile 0.01623 0.013279 0.014386 0.008115 0.016968 \n", "\n", " carries progressive_carries carries_into_final_third \\\n", "Immobile 0.267429 0.019181 0.011435 \n", "\n", " carries_into_penalty_area \n", "Immobile 0.011435 \n", "\n", "[1 rows x 125 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test = player_match_data_ext('Immobile', 'Lazio', 'Atalanta')\n", "\n", "add_columns = test.columns\n", "\n", "test" ] }, { "cell_type": "code", "execution_count": 11, "id": "3ae718d2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
matchdayplayerteamoppteamhomevotegoalsassistscards_malusfantavote
01MussoAtalantaTorino06.0-100.54.5
11Pezzella Giu.AtalantaTorino06.0000.06.0
21DjimsitiAtalantaTorino06.0000.06.0
31GosensAtalantaTorino05.5000.05.5
41PalominoAtalantaTorino06.5000.06.5
.................................
1064938TamezeVeronaLazio05.5000.05.5
1065038HonglaVeronaLazio07.0100.59.5
1065138LasagnaVeronaLazio07.0100.59.5
1065238CaprariVeronaLazio06.0000.06.0
1065338SimeoneVeronaLazio07.0100.010.0
\n", "

10654 rows × 10 columns

\n", "
" ], "text/plain": [ " matchday player team oppteam home vote goals assists \\\n", "0 1 Musso Atalanta Torino 0 6.0 -1 0 \n", "1 1 Pezzella Giu. Atalanta Torino 0 6.0 0 0 \n", "2 1 Djimsiti Atalanta Torino 0 6.0 0 0 \n", "3 1 Gosens Atalanta Torino 0 5.5 0 0 \n", "4 1 Palomino Atalanta Torino 0 6.5 0 0 \n", "... ... ... ... ... ... ... ... ... \n", "10649 38 Tameze Verona Lazio 0 5.5 0 0 \n", "10650 38 Hongla Verona Lazio 0 7.0 1 0 \n", "10651 38 Lasagna Verona Lazio 0 7.0 1 0 \n", "10652 38 Caprari Verona Lazio 0 6.0 0 0 \n", "10653 38 Simeone Verona Lazio 0 7.0 1 0 \n", "\n", " cards_malus fantavote \n", "0 0.5 4.5 \n", "1 0.0 6.0 \n", "2 0.0 6.0 \n", "3 0.0 5.5 \n", "4 0.0 6.5 \n", "... ... ... \n", "10649 0.0 5.5 \n", "10650 0.5 9.5 \n", "10651 0.5 9.5 \n", "10652 0.0 6.0 \n", "10653 0.0 10.0 \n", "\n", "[10654 rows x 10 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "votes = pd.read_excel('mid_outputs/season' + season + '/players_votes.xlsx', index_col = 0)\n", "votes" ] }, { "cell_type": "code", "execution_count": null, "id": "ec0bc56b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "200\n", "300\n", "400\n", "500\n", "600\n", "700\n", "800\n", "900\n", "1000\n", "1100\n", "1200\n", "1300\n", "1400\n", "1500\n", "1600\n", "1700\n", "1800\n", "2000\n", "2100\n", "2200\n", "2300\n", "2400\n", "2500\n", "2600\n", "2700\n", "2800\n", "2900\n", "3000\n", "3100\n", "3200\n", "3300\n", "3400\n", "3500\n", "3600\n", "3700\n", "3800\n", "3900\n", "4000\n", "4100\n", "4200\n", "4300\n", "4400\n", "4500\n", "4600\n", "4700\n", "4800\n", "4900\n", "5000\n", "5100\n" ] } ], "source": [ "db = votes.copy()\n", "\n", "delta = pd.DataFrame(columns = add_columns)\n", "\n", "for i in range(db.shape[0]):\n", " ext_data = player_match_data_ext(db['player'][i], db['team'][i], db['oppteam'][i])\n", " \n", " if(not isinstance(ext_data, pd.DataFrame)):\n", " continue\n", " \n", " ext_data = ext_data.rename(index = {db['player'][i] : i})\n", " \n", " delta = pd.concat([delta, ext_data], axis = 0)\n", " \n", " if(i % 100 == 0):\n", " print(i)\n", " \n", "db = pd.concat([db, delta], axis = 1)\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "b292f9f9", "metadata": {}, "outputs": [], "source": [ "db" ] }, { "cell_type": "code", "execution_count": null, "id": "1db9f77f", "metadata": {}, "outputs": [], "source": [ "db = db.drop(db[db.r == 'P'].index) # remove goalkeepers\n", "db = db.drop(db[db.r != db.r].index) # remove non extisting players\n", "db = db.drop(db[db.r != db.r].index) # remove non extisting players\n", "db = db.drop(db[db.xg != db.xg].index) \n" ] }, { "cell_type": "code", "execution_count": null, "id": "f56df3ca", "metadata": {}, "outputs": [], "source": [ "db" ] }, { "cell_type": "code", "execution_count": null, "id": "df26c8e0", "metadata": {}, "outputs": [], "source": [ "db.to_excel('mid_outputs/season' + season + '/database_entries.xlsx')" ] }, { "cell_type": "markdown", "id": "9f16e22b", "metadata": {}, "source": [ "Goalkeepers" ] }, { "cell_type": "code", "execution_count": 56, "id": "ba7b838c", "metadata": {}, "outputs": [], "source": [ "features_abs_gk = [\n", " 'gk_games',\n", " 'gk_games_starts',\n", " 'gk_minutes',\n", " 'gk_goals_against_per90', \n", " 'gk_save_pct',\n", " 'gk_clean_sheets_pct',\n", " 'gk_psxg_net_per90',\n", " 'gk_passes_pct_launched',\n", " 'gk_pct_passes_launched',\n", " 'gk_passes_length_avg',\n", " 'gk_pct_goal_kicks_launched',\n", " 'gk_goal_kick_length_avg',\n", " 'gk_crosses_stopped_pct',\n", " 'gk_def_actions_outside_pen_area_per90',\n", " 'gk_avg_distance_def_actions',\n", " \n", " 'team_possession',\n", " 'team_goals_assists_per90',\n", " 'team_goals_pens_per90',\n", " 'team_goals_assists_pens_per90',\n", " 'team_xg_per90',\n", " 'team_gk_goals_against_per90',\n", " 'team_gk_save_pct',\n", " 'team_gk_clean_sheets_pct',\n", " 'team_passes_pct',\n", " 'team_passes_pct_medium',\n", " 'team_passes_pct_long',\n", " 'team_sca_per90',\n", " 'team_gca_per90',\n", " 'team_dribble_tackles_pct',\n", " 'team_aerials_won_pct',\n", " 'vs_team_possession',\n", " 'vs_team_goals_per90',\n", " 'vs_team_assists_per90',\n", " 'vs_team_xg_per90',\n", " 'vs_team_gk_save_pct',\n", " 'vs_team_gk_clean_sheets_pct',\n", " 'vs_team_gk_pct_passes_launched',\n", " 'vs_team_gk_crosses_stopped_pct',\n", " 'vs_team_shots_on_target_per90',\n", " 'vs_team_passes_pct',\n", " 'vs_team_passes_pct_short',\n", " 'vs_team_passes_pct_medium',\n", " 'vs_team_passes_pct_long',\n", " 'vs_team_sca_per90',\n", " 'vs_team_gca_per90',\n", " 'vs_team_dribble_tackles_pct',\n", " 'vs_team_dribbles_completed_pct',\n", " 'vs_team_aerials_won_pct',\n", " 'opp_team_possession',\n", " 'opp_team_goals_assists_per90',\n", " 'opp_team_goals_pens_per90',\n", " 'opp_team_goals_assists_pens_per90',\n", " 'opp_team_xg_per90',\n", " 'opp_team_gk_goals_against_per90',\n", " 'opp_team_gk_save_pct',\n", " 'opp_team_gk_clean_sheets_pct',\n", " 'opp_team_passes_pct',\n", " 'opp_team_passes_pct_medium',\n", " 'opp_team_passes_pct_long',\n", " 'opp_team_sca_per90',\n", " 'opp_team_gca_per90',\n", " 'opp_team_dribble_tackles_pct',\n", " 'opp_team_aerials_won_pct',\n", " 'opp_vs_team_possession',\n", " 'opp_vs_team_goals_per90',\n", " 'opp_vs_team_assists_per90',\n", " 'opp_vs_team_xg_per90',\n", " 'opp_vs_team_gk_save_pct',\n", " 'opp_vs_team_gk_clean_sheets_pct',\n", " 'opp_vs_team_gk_pct_passes_launched',\n", " 'opp_vs_team_gk_crosses_stopped_pct',\n", " 'opp_vs_team_shots_on_target_per90',\n", " 'opp_vs_team_passes_pct',\n", " 'opp_vs_team_passes_pct_short',\n", " 'opp_vs_team_passes_pct_medium',\n", " 'opp_vs_team_passes_pct_long',\n", " 'opp_vs_team_sca_per90',\n", " 'opp_vs_team_gca_per90',\n", " 'opp_vs_team_dribble_tackles_pct',\n", " 'opp_vs_team_dribbles_completed_pct',\n", " 'opp_vs_team_aerials_won_pct',\n", " \n", " 'vote_avg',\n", " 'vote_std']\n", "\n", "features_rel_gk = [\n", " 'gk_shots_on_target_against',\n", " 'gk_saves',\n", " 'gk_free_kick_goals_against',\n", " 'gk_corner_kick_goals_against',\n", " 'gk_own_goals_against',\n", " 'gk_psxg',\n", " 'gk_psnpxg_per_shot_on_target_against',\n", " 'gk_psxg_net',\n", " 'gk_passes_completed_launched',\n", " 'gk_passes_launched',\n", " 'gk_passes',\n", " 'gk_passes_throws',\n", " 'gk_goal_kicks',\n", " 'gk_crosses',\n", " 'gk_crosses_stopped',\n", "]" ] }, { "cell_type": "code", "execution_count": 57, "id": "1d2682b9", "metadata": {}, "outputs": [], "source": [ "def player_match_data_ext_gk(player, pteam, oppteam):\n", " pdata = player_match_data(player, pteam, oppteam)\n", " \n", " if(not isinstance(pdata, pd.DataFrame)):\n", " return None\n", " \n", " if(pdata['gk_games'][0] <= 0):\n", " return None\n", " \n", " out = pd.concat([pdata[features_abs_gk], pdata[features_rel_gk]], axis = 1)\n", " \n", " out[features_rel_gk] = out[features_rel_gk] / max(pdata['minutes'][0], 1)\n", "\n", " return out\n", " " ] }, { "cell_type": "code", "execution_count": 58, "id": "bc6e9d52", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
gk_gamesgk_games_startsgk_minutesgk_goals_against_per90gk_save_pctgk_clean_sheets_pctgk_psxg_net_per90gk_passes_pct_launchedgk_pct_passes_launchedgk_passes_length_avg...gk_psxggk_psnpxg_per_shot_on_target_againstgk_psxg_netgk_passes_completed_launchedgk_passes_launchedgk_passesgk_passes_throwsgk_goal_kicksgk_crossesgk_crosses_stopped
Consigli37.037.03322.01.7167.88.1-0.1643.229.030.9...56.00.28-6.0186.0431.01219.0174.0246.0491.021.0
\n", "

1 rows × 98 columns

\n", "
" ], "text/plain": [ " gk_games gk_games_starts gk_minutes gk_goals_against_per90 \\\n", "Consigli 37.0 37.0 3322.0 1.71 \n", "\n", " gk_save_pct gk_clean_sheets_pct gk_psxg_net_per90 \\\n", "Consigli 67.8 8.1 -0.16 \n", "\n", " gk_passes_pct_launched gk_pct_passes_launched \\\n", "Consigli 43.2 29.0 \n", "\n", " gk_passes_length_avg ... gk_psxg \\\n", "Consigli 30.9 ... 56.0 \n", "\n", " gk_psnpxg_per_shot_on_target_against gk_psxg_net \\\n", "Consigli 0.28 -6.0 \n", "\n", " gk_passes_completed_launched gk_passes_launched gk_passes \\\n", "Consigli 186.0 431.0 1219.0 \n", "\n", " gk_passes_throws gk_goal_kicks gk_crosses gk_crosses_stopped \n", "Consigli 174.0 246.0 491.0 21.0 \n", "\n", "[1 rows x 98 columns]" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test = player_match_data_ext_gk('Consigli', 'Sassuolo', 'Atalanta')\n", "\n", "add_columns_gk = test.columns\n", "\n", "test" ] }, { "cell_type": "code", "execution_count": null, "id": "6f08e718", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "100\n", "200\n", "300\n", "400\n", "500\n", "600\n", "700\n", "800\n", "900\n", "1000\n", "1100\n", "1200\n", "1300\n", "1400\n", "1500\n", "1600\n", "1700\n", "1800\n", "1900\n", "2000\n", "2100\n", "2200\n", "2300\n", "2400\n", "2500\n", "2600\n", "2700\n", "2800\n", "2900\n", "3000\n", "3100\n", "3200\n", "3300\n", "3400\n", "3500\n", "3600\n", "3700\n", "3800\n", "3900\n", "4000\n", "4100\n", "4200\n", "4300\n", "4400\n", "4500\n", "4600\n", "4700\n", "4800\n", "4900\n", "5000\n", "5100\n", "5200\n", "5300\n", "5400\n", "5500\n", "5600\n", "5700\n", "5800\n", "5900\n", "6000\n", "6100\n", "6200\n", "6300\n", "6400\n", "6500\n", "6600\n", "6700\n", "6800\n", "6900\n", "7000\n", "7100\n", "7200\n" ] } ], "source": [ "db_gk = votes.copy()\n", "\n", "delta = pd.DataFrame(columns = add_columns_gk)\n", "\n", "for i in range(db_gk.shape[0]):\n", " ext_data = player_match_data_ext_gk(db_gk['player'][i], db_gk['team'][i], db_gk['oppteam'][i])\n", " \n", " if(i % 100 == 0):\n", " print(i)\n", " \n", " if(not isinstance(ext_data, pd.DataFrame)):\n", " continue\n", " \n", " ext_data = ext_data.rename(index = {db_gk['player'][i] : i})\n", " \n", " delta = pd.concat([delta, ext_data], axis = 0)\n", " \n", " \n", " \n", "db_gk = pd.concat([db_gk, delta], axis = 1)\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "2b540670", "metadata": {}, "outputs": [], "source": [ "db_gk = db_gk.drop(db_gk[db_gk.gk_games != db_gk.gk_games].index) # remove non extisting players" ] }, { "cell_type": "code", "execution_count": null, "id": "35495581", "metadata": {}, "outputs": [], "source": [ "db_gk.to_excel('mid_outputs/season' + season + '/database_entries_gk.xlsx')" ] }, { "cell_type": "code", "execution_count": null, "id": "43b85925", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }