Files
fantabeto/3_players_dataset_creation.ipynb
T
Giuseppe Musicco 1492328958 Code updated for Serie A 2023/2024
- Reorganization of data folders
- Code adapted for the new Serie A season, also considering only a small number of league games has been played
- Stats from other leagues are considered for players at their first Serie A season (rookies), for now without any adaptation based on league difficulty
- Minor fixes
2023-09-09 19:31:52 +02:00

3543 lines
128 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "b2cd2177",
"metadata": {},
"source": [
"Players dataset creation\n",
"\n",
"The Fantacalcio players list is manually downloaded from https://www.fantacalcio.it/quotazioni-fantacalcio\n",
"\n",
"Here, the players database is generated, by merging the Fantacalcio list to stats downloaded from http://fbref.com"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "7c65df92",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"id": "5ab35d0c",
"metadata": {},
"source": [
"Load fbref data for outfield players and goalkeepers.\n",
"\n",
"Generate fbref player list, adding player surname (with special characters replaced to normal ones)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "b2d7073e",
"metadata": {},
"outputs": [],
"source": [
"rcsv = pd.read_csv('fbref_data/outfield_players.csv') \n",
"outfield_players = pd.DataFrame(rcsv)\n",
"\n",
"rcsv = pd.read_csv('fbref_data/keepers_players.csv') \n",
"keeper_players = pd.DataFrame(rcsv)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "667970f6",
"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>player</th>\n",
" <th>team</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Michel Aebischer</td>\n",
" <td>Bologna</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Luis Alberto</td>\n",
" <td>Lazio</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Pontus Almqvist</td>\n",
" <td>Lecce</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Lorenzo Amatucci</td>\n",
" <td>Fiorentina</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Bruno Amione</td>\n",
" <td>Hellas Verona</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>419</th>\n",
" <td>Łukasz Skorupski</td>\n",
" <td>Bologna</td>\n",
" </tr>\n",
" <tr>\n",
" <th>420</th>\n",
" <td>Yann Sommer</td>\n",
" <td>Inter</td>\n",
" </tr>\n",
" <tr>\n",
" <th>421</th>\n",
" <td>Wojciech Szczęsny</td>\n",
" <td>Juventus</td>\n",
" </tr>\n",
" <tr>\n",
" <th>422</th>\n",
" <td>Pietro Terracciano</td>\n",
" <td>Fiorentina</td>\n",
" </tr>\n",
" <tr>\n",
" <th>423</th>\n",
" <td>Stefano Turati</td>\n",
" <td>Frosinone</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>424 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" player team\n",
"0 Michel Aebischer Bologna\n",
"1 Luis Alberto Lazio\n",
"2 Pontus Almqvist Lecce\n",
"3 Lorenzo Amatucci Fiorentina\n",
"4 Bruno Amione Hellas Verona\n",
".. ... ...\n",
"419 Łukasz Skorupski Bologna\n",
"420 Yann Sommer Inter\n",
"421 Wojciech Szczęsny Juventus\n",
"422 Pietro Terracciano Fiorentina\n",
"423 Stefano Turati Frosinone\n",
"\n",
"[424 rows x 2 columns]"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"players = pd.concat( [ outfield_players[['player', 'team']], keeper_players[['player', 'team']] ], axis = 0, ignore_index = True)\n",
"\n",
"keepers_ID = len(outfield_players)\n",
"\n",
"players"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "e1e64596",
"metadata": {},
"outputs": [],
"source": [
"import unicodedata\n",
"\n",
"def normalize_name(input_str):\n",
" nfkd_form = unicodedata.normalize('NFKD', input_str)\n",
" only_ascii = nfkd_form.encode('ASCII', 'ignore')\n",
" return only_ascii.decode('utf-8')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "3078d6f3",
"metadata": {},
"outputs": [],
"source": [
"players['surname'] = players['player']\n",
"players['initial'] = players['player']\n",
"\n",
"for i in range(players.shape[0]):\n",
" players['surname'][i] = players['surname'][i].split(' ')[-1]\n",
" players['surname'][i] = normalize_name(players['surname'][i]).replace('\\'', '')\n",
" \n",
" \n",
" players['initial'][i] = players['player'][i][0]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "ffd6091c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" player surname\n",
"0 Michel Aebischer Aebischer\n",
"1 Luis Alberto Alberto\n",
"2 Pontus Almqvist Almqvist\n",
"3 Lorenzo Amatucci Amatucci\n",
"4 Bruno Amione Amione\n",
"5 Felipe Anderson Anderson\n",
"6 Houssem Aouar Aouar\n",
"7 Marko Arnautović Arnautovic\n",
"8 Kristjan Asllani Asllani\n",
"9 Tommaso Augello Augello\n",
"10 Yann Aurel Bisseck Bisseck\n",
"11 Paulo Azzi Azzi\n",
"12 Oussama El Azzouzi Azzouzi\n",
"13 Milan Badelj Badelj\n",
"14 Jaime Báez Baez\n",
"15 Nedim Bajrami Bajrami\n",
"16 Mitchel Bakker Bakker\n",
"17 Tommaso Baldanzi Baldanzi\n",
"18 Lameck Banda Banda\n",
"19 Mattia Bani Bani\n",
"20 Nicolò Barella Barella\n",
"21 Enzo Barrenechea Barrenechea\n",
"22 Federico Baschirotto Baschirotto\n",
"23 Alessandro Bastoni Bastoni\n",
"24 Raoul Bellanova Bellanova\n",
"25 Andrea Belotti Belotti\n",
"26 Lucas Beltrán Beltran\n",
"27 Domenico Berardi Berardi\n",
"28 Bartosz Bereszyński Bereszynski\n",
"29 Etrit Berisha Berisha\n",
"30 Victor Bernth Kristiansen Kristiansen\n",
"31 Beto Beto\n",
"32 Sam Beukema Beukema\n",
"33 Jaka Bijol Bijol\n",
"34 Cristiano Biraghi Biraghi\n",
"35 Davide Biraschi Biraschi\n",
"36 Samuele Birindelli Birindelli\n",
"37 Alexis Blin Blin\n",
"38 Emil Bohinen Bohinen\n",
"39 Daniel Boloca Boloca\n",
"40 Giacomo Bonaventura Bonaventura\n",
"41 Federico Bonazzoli Bonazzoli\n",
"42 Warren Bondo Bondo\n",
"43 Gennaro Borrelli Borrelli\n",
"44 Erik Botheim Botheim\n",
"45 Edoardo Bove Bove\n",
"46 Domagoj Bradarić Bradaric\n",
"47 Josip Brekalo Brekalo\n",
"48 Gleison Bremer Bremer\n",
"49 Marco Brescianini Brescianini\n",
"50 Alessandro Buongiorno Buongiorno\n",
"51 Rareș-Cătălin Burnete Burnete\n",
"52 Juan Cabal Cabal\n",
"53 Jovane Cabral Cabral\n",
"54 Liberato Cacace Cacace\n",
"55 Jens Cajuste Cajuste\n",
"56 Davide Calabria Calabria\n",
"57 Luca Caldirola Caldirola\n",
"58 Hakan Çalhanoğlu Calhanoglu\n",
"59 Nicolò Cambiaghi Cambiaghi\n",
"60 Andrea Cambiaso Cambiaso\n",
"61 Matteo Cancellieri Cancellieri\n",
"62 Antonio Candreva Candreva\n",
"63 Luigi Canotto Canotto\n",
"64 Gianluca Caprari Caprari\n",
"65 Elia Caprile Caprile\n",
"66 Francesco Caputo Caputo\n",
"67 Andrea Carboni Carboni\n",
"68 Valentin Carboni Carboni\n",
"69 Carlos Carlos\n",
"70 Nicolò Casale Casale\n",
"71 Giuseppe Caso Caso\n",
"72 Valentín Castellanos Castellanos\n",
"73 Danilo Cataldi Cataldi\n",
"74 Emil Ceide Ceide\n",
"75 Zeki Çelik Celik\n",
"76 Michele Cerofolini Cerofolini\n",
"77 Walid Cheddira Cheddira\n",
"78 Federico Chiesa Chiesa\n",
"79 Oliver Christensen Christensen\n",
"80 Samuel Chukwueze Chukwueze\n",
"81 Patrick Ciurria Ciurria\n",
"82 Lorenzo Colombo Colombo\n",
"83 Andrea Colpani Colpani\n",
"84 Andrea Consigli Consigli\n",
"85 Diego Coppola Coppola\n",
"86 Tommaso Corazza Corazza\n",
"87 Lassana Coulibaly Coulibaly\n",
"88 Mamadou Coulibaly Coulibaly\n",
"89 Bryan Cristante Cristante\n",
"90 Juan Cuadrado Cuadrado\n",
"91 Marvin Cuni Cuni\n",
"92 Danilo D'Ambrosio DAmbrosio\n",
"93 Danilo Danilo\n",
"94 Matteo Darmian Darmian\n",
"95 Paweł Dawidowicz Dawidowicz\n",
"96 Charles De Ketelaere Ketelaere\n",
"97 Lorenzo De Silvestri Silvestri\n",
"98 Grégoire Defrel Defrel\n",
"99 Alessandro Deiola Deiola\n",
"100 Mattia Destro Destro\n",
"101 Federico Di Francesco Francesco\n",
"102 Michele Di Gregorio Gregorio\n",
"103 Giovanni Di Lorenzo Lorenzo\n",
"104 Alessandro Di Pardo Pardo\n",
"105 Boulaye Dia Dia\n",
"106 Federico Dimarco Dimarco\n",
"107 Berat Djimsiti Djimsiti\n",
"108 Dodô Dodo\n",
"109 Josh Doig Doig\n",
"110 Nicolás Domínguez Dominguez\n",
"111 Patrick Dorgu Dorgu\n",
"112 Alberto Dossena Dossena\n",
"113 Radu Drăgușin Dragusin\n",
"114 Ondrej Duda Duda\n",
"115 Denzel Dumfries Dumfries\n",
"116 Alfred Duncan Duncan\n",
"117 Paulo Dybala Dybala\n",
"118 Festy Ebosele Ebosele\n",
"119 Tyronne Ebuehi Ebuehi\n",
"120 Éderson Ederson\n",
"121 Emmanuel Ekong Ekong\n",
"122 Caleb Ekuban Ekuban\n",
"123 Elif Elmas Elmas\n",
"124 Martin Erlic Erlic\n",
"125 Giovanni Fabbian Fabbian\n",
"126 Nicolò Fagioli Fagioli\n",
"127 Wladimiro Falcone Falcone\n",
"128 Davide Faraoni Faraoni\n",
"129 Federico Fazio Fazio\n",
"130 Jacopo Fazzini Fazzini\n",
"131 Lewis Ferguson Ferguson\n",
"132 João Ferreira Ferreira\n",
"133 Alessandro Florenzi Florenzi\n",
"134 Michael Folorunsho Folorunsho\n",
"135 Davide Frattesi Frattesi\n",
"136 Morten Frendrup Frendrup\n",
"137 Roberto Gagliardini Gagliardini\n",
"138 Antonino Gallo Gallo\n",
"139 Luca Garritano Garritano\n",
"140 Federico Gatti Gatti\n",
"141 Francesco Gelli Gelli\n",
"142 Valentin Gendrey Gendrey\n",
"143 Olivier Giroud Giroud\n",
"144 Edoardo Goldaniga Goldaniga\n",
"145 Joan Gonzàlez Gonzalez\n",
"146 Nicolás González Gonzalez\n",
"147 Alberto Grassi Grassi\n",
"148 Mattéo Guendouzi Guendouzi\n",
"149 Albert Guðmundsson Gumundsson\n",
"150 Emmanuel Gyasi Gyasi\n",
"151 Norbert Gyömbér Gyomber\n",
"152 Nicolas Haas Haas\n",
"153 Abdou Harroui Harroui\n",
"154 Silvan Hefti Hefti\n",
"155 Liam Henderson Henderson\n",
"156 Matheus Henrique Henrique\n",
"157 Theo Hernández Hernandez\n",
"158 Isak Hien Hien\n",
"159 Emil Holm Holm\n",
"160 Martin Hongla Hongla\n",
"161 Sydney van Hooijdonk Hooijdonk\n",
"162 Elseid Hysaj Hysaj\n",
"163 Chukwubuikem Ikwuemesi Ikwuemesi\n",
"164 Ivan Ilić Ilic\n",
"165 Samuel Iling-Junior Iling-Junior\n",
"166 Ciro Immobile Immobile\n",
"167 Gino Infantino Infantino\n",
"168 Gustav Isaksen Isaksen\n",
"169 Ardian Ismajli Ismajli\n",
"170 Armando Izzo Izzo\n",
"171 Filip Jagiełło Jagieo\n",
"172 Jakub Jankto Jankto\n",
"173 Juan Jesus Jesus\n",
"174 Mohamed Kaba Kaba\n",
"175 Christian Kabasele Kabasele\n",
"176 Pierre Kalulu Kalulu\n",
"177 Daichi Kamada Kamada\n",
"178 Hassane Kamara Kamara\n",
"179 Yann Karamoh Karamoh\n",
"180 Jesper Karlsson Karlsson\n",
"181 Rick Karsdorp Karsdorp\n",
"182 Grigoris Kastanos Kastanos\n",
"183 Michael Kayode Kayode\n",
"184 Moise Kean Kean\n",
"185 Simon Kjær Kjr\n",
"186 Sead Kolašinac Kolasinac\n",
"187 Teun Koopmeiners Koopmeiners\n",
"188 Filip Kostić Kostic\n",
"189 Christian Kouamé Kouame\n",
"190 Viktor Kovalenko Kovalenko\n",
"191 Nikola Krstović Krstovic\n",
"192 Rade Krunić Krunic\n",
"193 Berkan Kutlu Kutlu\n",
"194 Khvicha Kvaratskhelia Kvaratskhelia\n",
"195 Giorgi Kvernadze Kvernadze\n",
"196 Giorgos Kyriakopoulos Kyriakopoulos\n",
"197 Armand Lauriente Lauriente\n",
"198 Valentino Lazaro Lazaro\n",
"199 Manuel Lazzari Lazzari\n",
"200 Rafael Leão Leao\n",
"201 Jesper Lindstrøm Lindstrm\n",
"202 Karol Linetty Linetty\n",
"203 Diego Llorente Llorente\n",
"204 Stanislav Lobotka Lobotka\n",
"205 Manuel Locatelli Locatelli\n",
"206 Ruben Loftus-Cheek Loftus-Cheek\n",
"207 Ademola Lookman Lookman\n",
"208 Maxime Lopez Lopez\n",
"209 Matteo Lovato Lovato\n",
"210 Sandi Lovrić Lovric\n",
"211 Lorenzo Lucca Lucca\n",
"212 Jhon Lucumí Lucumi\n",
"213 José Luis Palomino Palomino\n",
"214 Romelu Lukaku Lukaku\n",
"215 Sebastiano Luperto Luperto\n",
"216 Charalambos Lykogiannis Lykogiannis\n",
"217 Giulio Maggiore Maggiore\n",
"218 Giangiacomo Magnani Magnani\n",
"219 Mike Maignan Maignan\n",
"220 Antoine Makoumbou Makoumbou\n",
"221 Youssef Maleh Maleh\n",
"222 Ruslan Malinovskyi Malinovskyi\n",
"223 Gianluca Mancini Mancini\n",
"224 Rolando Mandragora Mandragora\n",
"225 Riccardo Marchizza Marchizza\n",
"226 Pablo Marí Mari\n",
"227 Mirko Marić Maric\n",
"228 Răzvan Marin Marin\n",
"229 Agustín Martegani Martegani\n",
"230 Aarón Martín Martin\n",
"231 Josep Martinez Martinez\n",
"232 Lautaro Martínez Martinez\n",
"233 Lucas Martínez Quarta Quarta\n",
"234 Adam Marušić Marusic\n",
"235 Luca Mazzitelli Mazzitelli\n",
"236 Pasquale Mazzocchi Mazzocchi\n",
"237 Jordi Mboula Mboula\n",
"238 Weston McKennie McKennie\n",
"239 Arthur Melo Melo\n",
"240 Alex Meret Meret\n",
"241 Nikola Milenković Milenkovic\n",
"242 Arkadiusz Milik Milik\n",
"243 Vanja Milinković-Savić Milinkovic-Savic\n",
"244 Kevin Miranda Miranda\n",
"245 Fabio Miretti Miretti\n",
"246 Filippo Missori Missori\n",
"247 Henrikh Mkhitaryan Mkhitaryan\n",
"248 Ilario Monterisi Monterisi\n",
"249 Lorenzo Montipò Montipo\n",
"250 Nikola Moro Moro\n",
"251 Dany Mota Mota\n",
"252 Samuele Mulattieri Mulattieri\n",
"253 Luis Muriel Muriel\n",
"254 Yunus Musah Musah\n",
"255 Juan Musso Musso\n",
"256 Nahitan Nández Nandez\n",
"257 Michel Ndary Adopo Adopo\n",
"258 Dan Ndoye Ndoye\n",
"259 Cyril Ngonge Ngonge\n",
"260 Rasmus Nissen Nissen\n",
"261 M'Bala Nzola Nzola\n",
"262 Adam Obert Obert\n",
"263 Guillermo Ochoa Ochoa\n",
"264 Noah Okafor Okafor\n",
"265 Mathías Olivera Olivera\n",
"266 Gaetano Oristanio Oristanio\n",
"267 Riccardo Orsolini Orsolini\n",
"268 Victor Osimhen Osimhen\n",
"269 Anthony Oyono Oyono\n",
"270 Riccardo Pagano Pagano\n",
"271 Leandro Paredes Paredes\n",
"272 Fabiano Parisi Parisi\n",
"273 Mario Pašalić Pasalic\n",
"274 Patric Patric\n",
"275 Rui Patrício Patricio\n",
"276 Leonardo Pavoletti Pavoletti\n",
"277 Marcus Pedersen Pedersen\n",
"278 Pedro Pedro\n",
"279 Pietro Pellegri Pellegri\n",
"280 Lorenzo Pellegrini Pellegrini\n",
"281 Luca Pellegrini Pellegrini\n",
"282 Pepín Pepin\n",
"283 Pedro Pereira Pereira\n",
"284 Nehuén Pérez Perez\n",
"285 Mattia Perin Perin\n",
"286 Samuele Perisan Perisan\n",
"287 Matteo Pessina Pessina\n",
"288 Andrea Petagna Petagna\n",
"289 Giuseppe Pezzella Pezzella\n",
"290 Roberto Piccoli Piccoli\n",
"291 Roberto Piccoli Piccoli\n",
"292 Andrea Pinamonti Pinamonti\n",
"293 Lorenzo Pirola Pirola\n",
"294 Tommaso Pobega Pobega\n",
"295 Paul Pogba Pogba\n",
"296 Matteo Politano Politano\n",
"297 Marin Pongračić Pongracic\n",
"298 Stefan Posch Posch\n",
"299 Ivan Provedel Provedel\n",
"300 Christian Pulisic Pulisic\n",
"301 Domingos Quina Quina\n",
"302 Adrien Rabiot Rabiot\n",
"303 Uroš Račić Racic\n",
"304 Nemanja Radonjić Radonjic\n",
"305 Boris Radunović Radunovic\n",
"306 Hamza Rafia Rafia\n",
"307 Ylber Ramadani Ramadani\n",
"308 Luca Ranieri Ranieri\n",
"309 Giacomo Raspadori Raspadori\n",
"310 Tijjani Reijnders Reijnders\n",
"311 Mateo Retegui Retegui\n",
"312 Samuele Ricci Ricci\n",
"313 Ricardo Rodríguez Rodriguez\n",
"314 Alessio Romagnoli Romagnoli\n",
"315 Simone Romagnoli Romagnoli\n",
"316 Marten de Roon Roon\n",
"317 Amir Rrahmani Rrahmani\n",
"318 Ruan Ruan\n",
"319 Matteo Ruggeri Ruggeri\n",
"320 Mário Rui Rui\n",
"321 Stefano Sabelli Sabelli\n",
"322 Lazar Samardzic Samardzic\n",
"323 Junior Sambia Sambia\n",
"324 Antonio Sanabria Sanabria\n",
"325 Renato Sanches Sanches\n",
"326 Alex Sandro Sandro\n",
"327 Riccardo Saponara Saponara\n",
"328 Giorgio Scalvini Scalvini\n",
"329 Gianluca Scamacca Scamacca\n",
"330 Perr Schuurs Schuurs\n",
"331 Demba Seck Seck\n",
"332 Vivaldo Semedo Semedo\n",
"333 Stefano Sensi Sensi\n",
"334 Suat Serdar Serdar\n",
"335 Stephan El Shaarawy Shaarawy\n",
"336 Eldor Shomurodov Shomurodov\n",
"337 Steven Shpendi Shpendi\n",
"338 Marco Silvestri Silvestri\n",
"339 Giovanni Simeone Simeone\n",
"340 Leo Skiri Østigård stigard\n",
"341 Łukasz Skorupski Skorupski\n",
"342 Chris Smalling Smalling\n",
"343 Ola Solbakken Solbakken\n",
"344 Yann Sommer Sommer\n",
"345 Riccardo Sottil Sottil\n",
"346 Matìas Soulé Soule\n",
"347 Leonardo Spinazzola Spinazzola\n",
"348 Gabriel Strefezza Strefezza\n",
"349 Kevin Strootman Strootman\n",
"350 Isaac Success Success\n",
"351 Ibrahim Sulemana Sulemana\n",
"352 Wojciech Szczęsny Szczesny\n",
"353 Przemysław Szymiński Szyminski\n",
"354 Adrien Tameze Tameze\n",
"355 Loum Tchaouna Tchaouna\n",
"356 Filippo Terracciano Terracciano\n",
"357 Pietro Terracciano Terracciano\n",
"358 Florian Thauvin Thauvin\n",
"359 Malick Thiaw Thiaw\n",
"360 Morten Thorsby Thorsby\n",
"361 Kristian Thorstvedt Thorstvedt\n",
"362 Marcus Thuram Thuram\n",
"363 Jeremy Toljan Toljan\n",
"364 Fikayo Tomori Tomori\n",
"365 Stefano Turati Turati\n",
"366 Kacper Urbanski Urbanski\n",
"367 Johan Vásquez Vasquez\n",
"368 Matías Vecino Vecino\n",
"369 Simone Verdi Verdi\n",
"370 Samuele Vignato Vignato\n",
"371 Matías Viña Vina\n",
"372 Mattia Viti Viti\n",
"373 Dušan Vlahović Vlahovic\n",
"374 Nikola Vlašić Vlasic\n",
"375 Mërgim Vojvoda Vojvoda\n",
"376 Cristian Volpato Volpato\n",
"377 Stefan de Vrij Vrij\n",
"378 Walace Walace\n",
"379 Sebastian Walukiewicz Walukiewicz\n",
"380 Timothy Weah Weah\n",
"381 Mateusz Wieteska Wieteska\n",
"382 Kenan Yıldız Yldz\n",
"383 Mattia Zaccagni Zaccagni\n",
"384 Nicola Zalewski Zalewski\n",
"385 Andre-Frank Zambo Anguissa Anguissa\n",
"386 Duván Zapata Zapata\n",
"387 Duván Zapata Zapata\n",
"388 Gabriele Zappa Zappa\n",
"389 Davide Zappacosta Zappacosta\n",
"390 Oier Zarraga Zarraga\n",
"391 Jordan Zemura Zemura\n",
"392 Piotr Zieliński Zielinski\n",
"393 David Zima Zima\n",
"394 Joshua Zirkzee Zirkzee\n",
"395 Zito Zito\n",
"396 Nadir Zortea Zortea\n",
"397 Milan Đurić uric\n",
"398 Mateusz Łęgowski egowski\n",
"399 Etrit Berisha Berisha\n",
"400 Elia Caprile Caprile\n",
"401 Michele Cerofolini Cerofolini\n",
"402 Oliver Christensen Christensen\n",
"403 Andrea Consigli Consigli\n",
"404 Michele Di Gregorio Gregorio\n",
"405 Wladimiro Falcone Falcone\n",
"406 Mike Maignan Maignan\n",
"407 Josep Martinez Martinez\n",
"408 Alex Meret Meret\n",
"409 Vanja Milinković-Savić Milinkovic-Savic\n",
"410 Lorenzo Montipò Montipo\n",
"411 Juan Musso Musso\n",
"412 Guillermo Ochoa Ochoa\n",
"413 Rui Patrício Patricio\n",
"414 Mattia Perin Perin\n",
"415 Samuele Perisan Perisan\n",
"416 Ivan Provedel Provedel\n",
"417 Boris Radunović Radunovic\n",
"418 Marco Silvestri Silvestri\n",
"419 Łukasz Skorupski Skorupski\n",
"420 Yann Sommer Sommer\n",
"421 Wojciech Szczęsny Szczesny\n",
"422 Pietro Terracciano Terracciano\n",
"423 Stefano Turati Turati\n"
]
}
],
"source": [
"print(players[['player', 'surname']].to_string())"
]
},
{
"cell_type": "markdown",
"id": "9ab06a5c",
"metadata": {},
"source": [
"Replace the surname for some specific players, according to config/name_fix.txt file.\n",
"\n",
"This is done for players for which the decoded fbref surname doesn't correspond to Fantacalcio list."
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "3e759b1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ostigard\n",
"Augusto\n",
"Kjaer\n",
"Djuric\n",
"Gudmundsson\n"
]
},
{
"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>FROM</th>\n",
" <th>TO</th>\n",
" <th>TEAM</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>stigard</td>\n",
" <td>Ostigard</td>\n",
" <td>Napoli</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Min-jae</td>\n",
" <td>Kim</td>\n",
" <td>Napoli</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Hjlund</td>\n",
" <td>Hojlund</td>\n",
" <td>Atalanta</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Gytkjr</td>\n",
" <td>Gytkjaer</td>\n",
" <td>Monza</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Carlos</td>\n",
" <td>Augusto</td>\n",
" <td>Inter</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Mhle</td>\n",
" <td>Maehle</td>\n",
" <td>Atalanta</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Kjr</td>\n",
" <td>Kjaer</td>\n",
" <td>Milan</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>uricic</td>\n",
" <td>Djuricic</td>\n",
" <td>Sampdoria</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>uric</td>\n",
" <td>Djuric</td>\n",
" <td>Hellas Verona</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Arthur</td>\n",
" <td>Cabral</td>\n",
" <td>Fiorentina</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Martinez</td>\n",
" <td>Alvarez</td>\n",
" <td>Sassuolo</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>Gumundsson</td>\n",
" <td>Gudmundsson</td>\n",
" <td>Genoa</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" FROM TO TEAM\n",
"0 stigard Ostigard Napoli\n",
"1 Min-jae Kim Napoli\n",
"2 Hjlund Hojlund Atalanta\n",
"3 Gytkjr Gytkjaer Monza\n",
"4 Carlos Augusto Inter\n",
"5 Mhle Maehle Atalanta\n",
"6 Kjr Kjaer Milan\n",
"7 uricic Djuricic Sampdoria\n",
"8 uric Djuric Hellas Verona\n",
"9 Arthur Cabral Fiorentina\n",
"10 Martinez Alvarez Sassuolo\n",
"11 Gumundsson Gudmundsson Genoa"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rcsv = pd.read_csv('config/name_fix.txt') \n",
"name_fix = pd.DataFrame(rcsv)\n",
"\n",
"for i in range(name_fix.shape[0]):\n",
" for j in range(players.shape[0]):\n",
" if(players['surname'][j].lower() == name_fix['FROM'][i].lower() and players['team'][j].lower() == name_fix['TEAM'][i].lower()):\n",
" players['surname'][j] = name_fix['TO'][i]\n",
" print(name_fix['TO'][i])\n",
"\n",
"name_fix\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "3c686d9f",
"metadata": {},
"source": [
"Load players from Fantacalcio list."
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "f96eaaa1",
"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>id</th>\n",
" <th>r</th>\n",
" <th>name</th>\n",
" <th>team</th>\n",
" <th>surname</th>\n",
" <th>initial</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4312</td>\n",
" <td>P</td>\n",
" <td>Maignan</td>\n",
" <td>Milan</td>\n",
" <td>Maignan</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>572</td>\n",
" <td>P</td>\n",
" <td>Meret</td>\n",
" <td>Napoli</td>\n",
" <td>Meret</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2428</td>\n",
" <td>P</td>\n",
" <td>Sommer</td>\n",
" <td>Inter</td>\n",
" <td>Sommer</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>453</td>\n",
" <td>P</td>\n",
" <td>Szczesny</td>\n",
" <td>Juventus</td>\n",
" <td>Szczesny</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2814</td>\n",
" <td>P</td>\n",
" <td>Provedel</td>\n",
" <td>Lazio</td>\n",
" <td>Provedel</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6242</td>\n",
" <td>A</td>\n",
" <td>Bidaoui</td>\n",
" <td>Frosinone</td>\n",
" <td>Bidaoui</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6418</td>\n",
" <td>A</td>\n",
" <td>Burnete</td>\n",
" <td>Lecce</td>\n",
" <td>Burnete</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>6419</td>\n",
" <td>A</td>\n",
" <td>Corfitzen</td>\n",
" <td>Lecce</td>\n",
" <td>Corfitzen</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>6427</td>\n",
" <td>A</td>\n",
" <td>Stewart</td>\n",
" <td>Salernitana</td>\n",
" <td>Stewart</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>6434</td>\n",
" <td>A</td>\n",
" <td>Yildiz</td>\n",
" <td>Juventus</td>\n",
" <td>Yildiz</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 6 columns</p>\n",
"</div>"
],
"text/plain": [
" id r name team surname initial\n",
"0 4312 P Maignan Milan Maignan \n",
"1 572 P Meret Napoli Meret \n",
"2 2428 P Sommer Inter Sommer \n",
"3 453 P Szczesny Juventus Szczesny \n",
"4 2814 P Provedel Lazio Provedel \n",
".. ... .. ... ... ... ...\n",
"530 6242 A Bidaoui Frosinone Bidaoui \n",
"531 6418 A Burnete Lecce Burnete \n",
"532 6419 A Corfitzen Lecce Corfitzen \n",
"533 6427 A Stewart Salernitana Stewart \n",
"534 6434 A Yildiz Juventus Yildiz \n",
"\n",
"[535 rows x 6 columns]"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc_data = pd.read_excel('fantacalcio/Quotazioni_Fantacalcio.xlsx', 'Tutti', header = 1)\n",
"\n",
"fc_players = fc_data [['Id', 'R', 'Nome', 'Squadra']]\n",
"\n",
"fc_players = fc_players.rename(columns = {'Id' : 'id', 'R': 'r', 'Nome' : 'name', 'Squadra' : 'team'})\n",
"\n",
"fc_players['surname'] = fc_players['name']\n",
"fc_players['initial'] = fc_players['name']\n",
"\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" spl = normalize_name( fc_players['name'][i].replace('\\'', '') ).split(' ')\n",
" if('.' in spl[-1]):\n",
" fc_players.loc[i, 'surname'] = spl[-2]\n",
" fc_players.loc[i, 'initial'] = spl[-1][0]\n",
" else:\n",
" fc_players.loc[i, 'surname'] = spl[-1]\n",
" fc_players.loc[i, 'initial'] = ''\n",
" \n",
"fc_players\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "d944c720",
"metadata": {},
"source": [
"Associate players from Fantacalcio list to ID for FBref data."
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "9c50e4b5",
"metadata": {},
"outputs": [],
"source": [
"fc_players['fb_ID'] = fc_players['id']\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" fc_players.loc[i, 'fb_ID'] = -1\n",
" \n",
" for j in range(players.shape[0]):\n",
" if(fc_players['team'][i].lower() in players['team'][j].lower()):\n",
" if(fc_players['surname'][i].lower() == players['surname'][j].lower()): \n",
" # if(fc_players['initial'][i] == '' or fc_players['initial'][i].lower() == players['initial'][j].lower()):\n",
" if((fc_players['r'][i] == 'P') == (j >= keepers_ID)): # check wether they're a goalkeeper for both FBREF and Fantacalcio\n",
" fc_players.loc[i, 'fb_ID'] = j\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"id": "4e60fd2e",
"metadata": {},
"source": [
"Print players for which the association failed.\n",
"\n",
"Most of them are players who didn't play a single Serie A game this season with their team. If that is the case, and there is data from their previous team, that is taken here.\n",
"\n",
"Others are ones for which the FBRef surname doesn't correspond to Fantacalcio one.\n",
"\n",
"\n",
"For example, Cabral is Arthur for FBref.\n",
"\n",
"Correction is made in the name_fix code above."
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "18f6c5f2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Carnesecchi not found\n",
"Cragno not found\n",
"Sportiello not found\n",
"Mirante not found\n",
"Sepe not found\n",
"Leali not found\n",
"Lamanna not found\n",
"Sommariva not found\n",
"Pegolo not found\n",
"Perilli not found\n",
"Padelli not found\n",
"Scuffet not found\n",
"Gollini not found\n",
"Audero not found\n",
"Di Gennaro not found\n",
"Pinsoglio not found\n",
"Aresti not found\n",
"Fiorillo not found\n",
"Rossi F. not found\n",
"Costil not found\n",
"Ravaglia F. not found\n",
"Frattali not found\n",
"Contini not found\n",
"Brancolini not found\n",
"Berardi A. not found\n",
"Gemello not found\n",
"Boer not found\n",
"Bagnolini not found\n",
"Svilar not found\n",
"Sorrentino A. not found\n",
"Martinelli T. not found\n",
"Popa not found\n",
"Stubljar not found\n",
"Gori not found\n",
"Borbei not found\n",
"Okoye not found\n",
"Mandas not found\n",
"Pavard not found\n",
"Acerbi not found\n",
"Toloi not found\n",
"N'dicka not found\n",
"Bastoni S. not found\n",
"Kristensen not found\n",
"Natan not found\n",
"Mina not found\n",
"Hateboer not found\n",
"Masina not found\n",
"Djidji not found\n",
"Tressoldi not found\n",
"Hatzidiakos not found\n",
"Calafiori not found\n",
"Ehizibue not found\n",
"Vogliacco not found\n",
"Ferrari G. not found\n",
"Lirola not found\n",
"Venuti not found\n",
"Gunter not found\n",
"Soumaoro not found\n",
"Zanoli not found\n",
"Touba not found\n",
"Sazonov not found\n",
"Rugani not found\n",
"De Sciglio not found\n",
"Bonifazi not found\n",
"Kumbulla not found\n",
"Daniliuc not found\n",
"Haps not found\n",
"De Winter not found\n",
"Cittadini not found\n",
"Ebosse not found\n",
"Kristensen T. not found\n",
"Dermaku not found\n",
"Tonelli not found\n",
"Capradossi not found\n",
"Bettella not found\n",
"Okoli not found\n",
"Amey not found\n",
"Soppy not found\n",
"Gila not found\n",
"Guessand A. not found\n",
"Bronn not found\n",
"Guarino not found\n",
"Smajlovic not found\n",
"Matturro not found\n",
"N'guessan not found\n",
"Mateus Lusuardi not found\n",
"Kalaj not found\n",
"Pierozzi not found\n",
"Huijsen not found\n",
"Bonfanti not found\n",
"Pellegrino not found\n",
"Lindstrom not found\n",
"Lazovic not found\n",
"Ikone' not found\n",
"Barak not found\n",
"Bennacer not found\n",
"Klaassen not found\n",
"Castrovilli not found\n",
"Miranchuk not found\n",
"Messias not found\n",
"Reinier not found\n",
"Freuler not found\n",
"Lopez M. from previous team stats\n",
"Mancosu not found\n",
"Machin not found\n",
"Oudin not found\n",
"Cajuste not found\n",
"Castillejo not found\n",
"Iling Junior not found\n",
"Payero not found\n",
"Bourabia not found\n",
"Rovella not found\n",
"Saelemaekers not found\n",
"Maldini not found\n",
"Ranocchia F. not found\n",
"Tchatchoua not found\n",
"Romero L. not found\n",
"Basic not found\n",
"Suslov not found\n",
"Gaetano not found\n",
"Jagiello not found\n",
"Obiang not found\n",
"Akpa Akpro not found\n",
"Hrustic not found\n",
"Camara E. not found\n",
"Viola not found\n",
"Lulic K. not found\n",
"Rog not found\n",
"Nicolussi Caviglia not found\n",
"Demme not found\n",
"Pafundi not found\n",
"Adli not found\n",
"Zerbin not found\n",
"Faticanti not found\n",
"Gineitis not found\n",
"Belardinelli not found\n",
"Lipani not found\n",
"Joselito not found\n",
"Legowski not found\n",
"Prati not found\n",
"Toure' E. not found\n",
"Lapadula not found\n",
"Sanchez not found\n",
"Abraham not found\n",
"Deulofeu not found\n",
"Jovic not found\n",
"Azmoun not found\n",
"Henry not found\n",
"Davis K. not found\n",
"Brenner not found\n",
"Luvumbo not found\n",
"Jovane not found\n",
"Alvarez A. not found\n",
"Puscas not found\n",
"Ake' M. not found\n",
"Braaf not found\n",
"Kallon not found\n",
"Kaio Jorge not found\n",
"Valencia D. not found\n",
"Vivaldo not found\n",
"Bidaoui not found\n",
"Corfitzen not found\n",
"Stewart not found\n",
"Yildiz not found\n"
]
}
],
"source": [
"exceptions = ['pellegrini', 'bastoni'] # exceptions for such players that have the same surname as others (Berardi A., Luca Pellegrini)\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" if(fc_players['fb_ID'][i] == -1):\n",
" found = False\n",
" for j in range(players.shape[0]):\n",
" if(fc_players['surname'][i].lower() == players['surname'][j].lower()):\n",
" if(not(players['surname'][j].lower() in exceptions)):\n",
" if((fc_players['r'][i] == 'P') == (j >= keepers_ID)):\n",
" fc_players.loc[i, 'fb_ID']= j\n",
" found = True\n",
" if(found):\n",
" print(fc_players['name'][i] + ' from previous team stats')\n",
" else:\n",
" print(fc_players['name'][i] + ' not found')"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "3b4a36af",
"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>id</th>\n",
" <th>r</th>\n",
" <th>name</th>\n",
" <th>team</th>\n",
" <th>surname</th>\n",
" <th>initial</th>\n",
" <th>fb_ID</th>\n",
" <th>age</th>\n",
" <th>birth_year</th>\n",
" <th>games</th>\n",
" <th>...</th>\n",
" <th>gk_passes_length_avg</th>\n",
" <th>gk_goal_kicks</th>\n",
" <th>gk_pct_goal_kicks_launched</th>\n",
" <th>gk_goal_kick_length_avg</th>\n",
" <th>gk_crosses</th>\n",
" <th>gk_crosses_stopped</th>\n",
" <th>gk_crosses_stopped_pct</th>\n",
" <th>gk_def_actions_outside_pen_area</th>\n",
" <th>gk_def_actions_outside_pen_area_per90</th>\n",
" <th>gk_avg_distance_def_actions</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4312</td>\n",
" <td>P</td>\n",
" <td>Maignan</td>\n",
" <td>Milan</td>\n",
" <td>Maignan</td>\n",
" <td></td>\n",
" <td>406</td>\n",
" <td>28-068</td>\n",
" <td>1995</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>30.5</td>\n",
" <td>20</td>\n",
" <td>65.0</td>\n",
" <td>49.3</td>\n",
" <td>43</td>\n",
" <td>12</td>\n",
" <td>27.9</td>\n",
" <td>3</td>\n",
" <td>1.00</td>\n",
" <td>10.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>572</td>\n",
" <td>P</td>\n",
" <td>Meret</td>\n",
" <td>Napoli</td>\n",
" <td>Meret</td>\n",
" <td></td>\n",
" <td>408</td>\n",
" <td>26-171</td>\n",
" <td>1997</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>24.4</td>\n",
" <td>8</td>\n",
" <td>0.0</td>\n",
" <td>21.4</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" <td>6.7</td>\n",
" <td>5</td>\n",
" <td>1.67</td>\n",
" <td>18.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2428</td>\n",
" <td>P</td>\n",
" <td>Sommer</td>\n",
" <td>Inter</td>\n",
" <td>Sommer</td>\n",
" <td></td>\n",
" <td>420</td>\n",
" <td>34-266</td>\n",
" <td>1988</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>31.4</td>\n",
" <td>21</td>\n",
" <td>23.8</td>\n",
" <td>31.0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>2.9</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>6.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>453</td>\n",
" <td>P</td>\n",
" <td>Szczesny</td>\n",
" <td>Juventus</td>\n",
" <td>Szczesny</td>\n",
" <td></td>\n",
" <td>421</td>\n",
" <td>33-144</td>\n",
" <td>1990</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>31.6</td>\n",
" <td>3</td>\n",
" <td>66.7</td>\n",
" <td>53.3</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>6.3</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>10.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2814</td>\n",
" <td>P</td>\n",
" <td>Provedel</td>\n",
" <td>Lazio</td>\n",
" <td>Provedel</td>\n",
" <td></td>\n",
" <td>416</td>\n",
" <td>29-176</td>\n",
" <td>1994</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>26.1</td>\n",
" <td>11</td>\n",
" <td>27.3</td>\n",
" <td>31.6</td>\n",
" <td>39</td>\n",
" <td>2</td>\n",
" <td>5.1</td>\n",
" <td>6</td>\n",
" <td>2.00</td>\n",
" <td>16.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6242</td>\n",
" <td>A</td>\n",
" <td>Bidaoui</td>\n",
" <td>Frosinone</td>\n",
" <td>Bidaoui</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6418</td>\n",
" <td>A</td>\n",
" <td>Burnete</td>\n",
" <td>Lecce</td>\n",
" <td>Burnete</td>\n",
" <td></td>\n",
" <td>51</td>\n",
" <td>19-221</td>\n",
" <td>2004</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>6419</td>\n",
" <td>A</td>\n",
" <td>Corfitzen</td>\n",
" <td>Lecce</td>\n",
" <td>Corfitzen</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>6427</td>\n",
" <td>A</td>\n",
" <td>Stewart</td>\n",
" <td>Salernitana</td>\n",
" <td>Stewart</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>6434</td>\n",
" <td>A</td>\n",
" <td>Yildiz</td>\n",
" <td>Juventus</td>\n",
" <td>Yildiz</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 158 columns</p>\n",
"</div>"
],
"text/plain": [
" id r name team surname initial fb_ID age \\\n",
"0 4312 P Maignan Milan Maignan 406 28-068 \n",
"1 572 P Meret Napoli Meret 408 26-171 \n",
"2 2428 P Sommer Inter Sommer 420 34-266 \n",
"3 453 P Szczesny Juventus Szczesny 421 33-144 \n",
"4 2814 P Provedel Lazio Provedel 416 29-176 \n",
".. ... .. ... ... ... ... ... ... \n",
"530 6242 A Bidaoui Frosinone Bidaoui -1 0 \n",
"531 6418 A Burnete Lecce Burnete 51 19-221 \n",
"532 6419 A Corfitzen Lecce Corfitzen -1 0 \n",
"533 6427 A Stewart Salernitana Stewart -1 0 \n",
"534 6434 A Yildiz Juventus Yildiz -1 0 \n",
"\n",
" birth_year games ... gk_passes_length_avg gk_goal_kicks \\\n",
"0 1995 0 ... 30.5 20 \n",
"1 1997 0 ... 24.4 8 \n",
"2 1988 0 ... 31.4 21 \n",
"3 1990 0 ... 31.6 3 \n",
"4 1994 0 ... 26.1 11 \n",
".. ... ... ... ... ... \n",
"530 0 0 ... 0.0 0 \n",
"531 2004 1 ... 0.0 0 \n",
"532 0 0 ... 0.0 0 \n",
"533 0 0 ... 0.0 0 \n",
"534 0 0 ... 0.0 0 \n",
"\n",
" gk_pct_goal_kicks_launched gk_goal_kick_length_avg gk_crosses \\\n",
"0 65.0 49.3 43 \n",
"1 0.0 21.4 15 \n",
"2 23.8 31.0 35 \n",
"3 66.7 53.3 16 \n",
"4 27.3 31.6 39 \n",
".. ... ... ... \n",
"530 0.0 0.0 0 \n",
"531 0.0 0.0 0 \n",
"532 0.0 0.0 0 \n",
"533 0.0 0.0 0 \n",
"534 0.0 0.0 0 \n",
"\n",
" gk_crosses_stopped gk_crosses_stopped_pct \\\n",
"0 12 27.9 \n",
"1 1 6.7 \n",
"2 1 2.9 \n",
"3 1 6.3 \n",
"4 2 5.1 \n",
".. ... ... \n",
"530 0 0.0 \n",
"531 0 0.0 \n",
"532 0 0.0 \n",
"533 0 0.0 \n",
"534 0 0.0 \n",
"\n",
" gk_def_actions_outside_pen_area gk_def_actions_outside_pen_area_per90 \\\n",
"0 3 1.00 \n",
"1 5 1.67 \n",
"2 0 0.00 \n",
"3 0 0.00 \n",
"4 6 2.00 \n",
".. ... ... \n",
"530 0 0.00 \n",
"531 0 0.00 \n",
"532 0 0.00 \n",
"533 0 0.00 \n",
"534 0 0.00 \n",
"\n",
" gk_avg_distance_def_actions \n",
"0 10.3 \n",
"1 18.1 \n",
"2 6.8 \n",
"3 10.8 \n",
"4 16.3 \n",
".. ... \n",
"530 0.0 \n",
"531 0.0 \n",
"532 0.0 \n",
"533 0.0 \n",
"534 0.0 \n",
"\n",
"[535 rows x 158 columns]"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc_players"
]
},
{
"cell_type": "markdown",
"id": "f06afbb6",
"metadata": {},
"source": [
"Populate players dataset with stats from FBref, for outfield players and goalkeepers"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "1d73a312",
"metadata": {},
"outputs": [],
"source": [
"#Data for Outfield players\n",
"columns_to_copy = outfield_players.columns[4:]\n",
"\n",
"fc_players[columns_to_copy] = 0\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" if(fc_players['fb_ID'][i] != -1 and fc_players['r'][i] != 'P'):\n",
" for j in range(columns_to_copy.shape[0]):\n",
" #fc_players[columns_to_copy[j]][i] = outfield_players[columns_to_copy[j]][fc_players['fb_ID'][i]]\n",
" fc_players.loc[i, columns_to_copy[j]] = outfield_players.loc[fc_players['fb_ID'][i], columns_to_copy[j]]\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "7acb93e3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['age', 'birth_year', 'gk_games', 'gk_games_starts', 'gk_minutes',\n",
" 'gk_goals_against', 'gk_goals_against_per90',\n",
" 'gk_shots_on_target_against', 'gk_saves', 'gk_save_pct', 'gk_wins',\n",
" 'gk_ties', 'gk_losses', 'gk_clean_sheets', 'gk_clean_sheets_pct',\n",
" 'gk_pens_att', 'gk_pens_allowed', 'gk_pens_saved', 'gk_pens_missed',\n",
" 'minutes_90s', 'gk_free_kick_goals_against',\n",
" 'gk_corner_kick_goals_against', 'gk_own_goals_against', 'gk_psxg',\n",
" 'gk_psnpxg_per_shot_on_target_against', 'gk_psxg_net',\n",
" 'gk_psxg_net_per90', 'gk_passes_completed_launched',\n",
" 'gk_passes_launched', 'gk_passes_pct_launched', 'gk_passes',\n",
" 'gk_passes_throws', 'gk_pct_passes_launched', 'gk_passes_length_avg',\n",
" 'gk_goal_kicks', 'gk_pct_goal_kicks_launched',\n",
" 'gk_goal_kick_length_avg', 'gk_crosses', 'gk_crosses_stopped',\n",
" 'gk_crosses_stopped_pct', 'gk_def_actions_outside_pen_area',\n",
" 'gk_def_actions_outside_pen_area_per90', 'gk_avg_distance_def_actions'],\n",
" dtype='object')"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"keeper_players.columns[4:]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "eb9127a9",
"metadata": {},
"outputs": [],
"source": [
"#Data for Keepers\n",
"columns_to_copy = keeper_players.columns[4:]\n",
"\n",
"fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"\n",
"delta_k = outfield_players.shape[0]\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" if(fc_players['fb_ID'][i] != -1 and fc_players['r'][i] == 'P'):\n",
" for j in range(columns_to_copy.shape[0]):\n",
" #fc_players[columns_to_copy[j]][i] = keeper_players[columns_to_copy[j]][fc_players['fb_ID'][i] - delta_k]\n",
" fc_players.loc[i, columns_to_copy[j]] = keeper_players.loc[fc_players['fb_ID'][i] - delta_k, columns_to_copy[j]]"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "da977789",
"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>id</th>\n",
" <th>r</th>\n",
" <th>name</th>\n",
" <th>team</th>\n",
" <th>surname</th>\n",
" <th>initial</th>\n",
" <th>fb_ID</th>\n",
" <th>age</th>\n",
" <th>birth_year</th>\n",
" <th>games</th>\n",
" <th>...</th>\n",
" <th>gk_passes_length_avg</th>\n",
" <th>gk_goal_kicks</th>\n",
" <th>gk_pct_goal_kicks_launched</th>\n",
" <th>gk_goal_kick_length_avg</th>\n",
" <th>gk_crosses</th>\n",
" <th>gk_crosses_stopped</th>\n",
" <th>gk_crosses_stopped_pct</th>\n",
" <th>gk_def_actions_outside_pen_area</th>\n",
" <th>gk_def_actions_outside_pen_area_per90</th>\n",
" <th>gk_avg_distance_def_actions</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4312</td>\n",
" <td>P</td>\n",
" <td>Maignan</td>\n",
" <td>Milan</td>\n",
" <td>Maignan</td>\n",
" <td></td>\n",
" <td>406</td>\n",
" <td>28-068</td>\n",
" <td>1995</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>30.5</td>\n",
" <td>20</td>\n",
" <td>65.0</td>\n",
" <td>49.3</td>\n",
" <td>43</td>\n",
" <td>12</td>\n",
" <td>27.9</td>\n",
" <td>3</td>\n",
" <td>1.00</td>\n",
" <td>10.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>572</td>\n",
" <td>P</td>\n",
" <td>Meret</td>\n",
" <td>Napoli</td>\n",
" <td>Meret</td>\n",
" <td></td>\n",
" <td>408</td>\n",
" <td>26-171</td>\n",
" <td>1997</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>24.4</td>\n",
" <td>8</td>\n",
" <td>0.0</td>\n",
" <td>21.4</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" <td>6.7</td>\n",
" <td>5</td>\n",
" <td>1.67</td>\n",
" <td>18.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2428</td>\n",
" <td>P</td>\n",
" <td>Sommer</td>\n",
" <td>Inter</td>\n",
" <td>Sommer</td>\n",
" <td></td>\n",
" <td>420</td>\n",
" <td>34-266</td>\n",
" <td>1988</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>31.4</td>\n",
" <td>21</td>\n",
" <td>23.8</td>\n",
" <td>31.0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>2.9</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>6.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>453</td>\n",
" <td>P</td>\n",
" <td>Szczesny</td>\n",
" <td>Juventus</td>\n",
" <td>Szczesny</td>\n",
" <td></td>\n",
" <td>421</td>\n",
" <td>33-144</td>\n",
" <td>1990</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>31.6</td>\n",
" <td>3</td>\n",
" <td>66.7</td>\n",
" <td>53.3</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>6.3</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>10.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2814</td>\n",
" <td>P</td>\n",
" <td>Provedel</td>\n",
" <td>Lazio</td>\n",
" <td>Provedel</td>\n",
" <td></td>\n",
" <td>416</td>\n",
" <td>29-176</td>\n",
" <td>1994</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>26.1</td>\n",
" <td>11</td>\n",
" <td>27.3</td>\n",
" <td>31.6</td>\n",
" <td>39</td>\n",
" <td>2</td>\n",
" <td>5.1</td>\n",
" <td>6</td>\n",
" <td>2.00</td>\n",
" <td>16.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6242</td>\n",
" <td>A</td>\n",
" <td>Bidaoui</td>\n",
" <td>Frosinone</td>\n",
" <td>Bidaoui</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6418</td>\n",
" <td>A</td>\n",
" <td>Burnete</td>\n",
" <td>Lecce</td>\n",
" <td>Burnete</td>\n",
" <td></td>\n",
" <td>51</td>\n",
" <td>19-221</td>\n",
" <td>2004</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>6419</td>\n",
" <td>A</td>\n",
" <td>Corfitzen</td>\n",
" <td>Lecce</td>\n",
" <td>Corfitzen</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>6427</td>\n",
" <td>A</td>\n",
" <td>Stewart</td>\n",
" <td>Salernitana</td>\n",
" <td>Stewart</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>6434</td>\n",
" <td>A</td>\n",
" <td>Yildiz</td>\n",
" <td>Juventus</td>\n",
" <td>Yildiz</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 158 columns</p>\n",
"</div>"
],
"text/plain": [
" id r name team surname initial fb_ID age \\\n",
"0 4312 P Maignan Milan Maignan 406 28-068 \n",
"1 572 P Meret Napoli Meret 408 26-171 \n",
"2 2428 P Sommer Inter Sommer 420 34-266 \n",
"3 453 P Szczesny Juventus Szczesny 421 33-144 \n",
"4 2814 P Provedel Lazio Provedel 416 29-176 \n",
".. ... .. ... ... ... ... ... ... \n",
"530 6242 A Bidaoui Frosinone Bidaoui -1 0 \n",
"531 6418 A Burnete Lecce Burnete 51 19-221 \n",
"532 6419 A Corfitzen Lecce Corfitzen -1 0 \n",
"533 6427 A Stewart Salernitana Stewart -1 0 \n",
"534 6434 A Yildiz Juventus Yildiz -1 0 \n",
"\n",
" birth_year games ... gk_passes_length_avg gk_goal_kicks \\\n",
"0 1995 0 ... 30.5 20 \n",
"1 1997 0 ... 24.4 8 \n",
"2 1988 0 ... 31.4 21 \n",
"3 1990 0 ... 31.6 3 \n",
"4 1994 0 ... 26.1 11 \n",
".. ... ... ... ... ... \n",
"530 0 0 ... 0.0 0 \n",
"531 2004 1 ... 0.0 0 \n",
"532 0 0 ... 0.0 0 \n",
"533 0 0 ... 0.0 0 \n",
"534 0 0 ... 0.0 0 \n",
"\n",
" gk_pct_goal_kicks_launched gk_goal_kick_length_avg gk_crosses \\\n",
"0 65.0 49.3 43 \n",
"1 0.0 21.4 15 \n",
"2 23.8 31.0 35 \n",
"3 66.7 53.3 16 \n",
"4 27.3 31.6 39 \n",
".. ... ... ... \n",
"530 0.0 0.0 0 \n",
"531 0.0 0.0 0 \n",
"532 0.0 0.0 0 \n",
"533 0.0 0.0 0 \n",
"534 0.0 0.0 0 \n",
"\n",
" gk_crosses_stopped gk_crosses_stopped_pct \\\n",
"0 12 27.9 \n",
"1 1 6.7 \n",
"2 1 2.9 \n",
"3 1 6.3 \n",
"4 2 5.1 \n",
".. ... ... \n",
"530 0 0.0 \n",
"531 0 0.0 \n",
"532 0 0.0 \n",
"533 0 0.0 \n",
"534 0 0.0 \n",
"\n",
" gk_def_actions_outside_pen_area gk_def_actions_outside_pen_area_per90 \\\n",
"0 3 1.00 \n",
"1 5 1.67 \n",
"2 0 0.00 \n",
"3 0 0.00 \n",
"4 6 2.00 \n",
".. ... ... \n",
"530 0 0.00 \n",
"531 0 0.00 \n",
"532 0 0.00 \n",
"533 0 0.00 \n",
"534 0 0.00 \n",
"\n",
" gk_avg_distance_def_actions \n",
"0 10.3 \n",
"1 18.1 \n",
"2 6.8 \n",
"3 10.8 \n",
"4 16.3 \n",
".. ... \n",
"530 0.0 \n",
"531 0.0 \n",
"532 0.0 \n",
"533 0.0 \n",
"534 0.0 \n",
"\n",
"[535 rows x 158 columns]"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc_players"
]
},
{
"cell_type": "markdown",
"id": "81a17f84",
"metadata": {},
"source": [
"Load votes database, to add data to players database (mean vote and its standard deviation)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "6a0e43cd",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"votes = pd.read_excel('mid_outputs/players_votes.xlsx', index_col = 0)"
]
},
{
"cell_type": "markdown",
"id": "6c1b733a",
"metadata": {},
"source": [
"Compute the average Serie A Goal Keeper mean vote and vote std"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "61fac91a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"vote_avg 6.020000\n",
"vote_std 0.206692\n",
"dtype: float64\n"
]
},
{
"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>vote_avg</th>\n",
" <th>vote_std</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5.833333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>7.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>6.166667</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>5.666667</td>\n",
" <td>0.471405</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>6.500000</td>\n",
" <td>0.707107</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>6.166667</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>6.000000</td>\n",
" <td>0.408248</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>6.500000</td>\n",
" <td>0.408248</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>5.500000</td>\n",
" <td>0.408248</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>6.500000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>5.666667</td>\n",
" <td>0.849837</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>6.333333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>5.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>5.833333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>6.333333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>5.750000</td>\n",
" <td>0.250000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>6.500000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>6.500000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>5.750000</td>\n",
" <td>0.250000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>5.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" vote_avg vote_std\n",
"0 6.000000 0.000000\n",
"1 5.833333 0.235702\n",
"2 6.000000 0.000000\n",
"3 7.000000 0.000000\n",
"4 6.166667 0.235702\n",
"5 5.666667 0.471405\n",
"6 6.500000 0.707107\n",
"7 6.166667 0.235702\n",
"8 6.000000 0.408248\n",
"9 6.000000 0.000000\n",
"10 6.500000 0.408248\n",
"11 5.500000 0.408248\n",
"12 6.500000 0.000000\n",
"13 5.666667 0.849837\n",
"14 6.333333 0.235702\n",
"15 6.000000 0.000000\n",
"16 5.000000 0.000000\n",
"17 5.833333 0.235702\n",
"18 6.333333 0.235702\n",
"19 5.750000 0.250000\n",
"20 6.000000 0.000000\n",
"21 6.500000 0.000000\n",
"22 6.500000 0.000000\n",
"23 5.750000 0.250000\n",
"24 5.000000 0.000000"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"min_votes = 2 # TO BE UPDATED WHEN SERIE A HAS MORE CALENDAR WEEKS PLAYED\n",
"\n",
"perf_df_P = pd.DataFrame(columns = ['vote_avg', 'vote_std'])\n",
"\n",
"for i in range(fc_players.shape[0]): \n",
" if(fc_players.loc[i]['r'] == 'P'):\n",
" v = np.array([])\n",
" for j in range(votes.shape[0]):\n",
" if(fc_players['name'][i] == votes['player'][j]):\n",
" v = np.append(v, votes['vote'][j])\n",
"\n",
" if(v.shape[0] >= min_votes - 1):\n",
" row_df = pd.DataFrame(data = [[np.mean(v), np.std(v)]], columns = perf_df_P.columns)\n",
" perf_df_P = pd.concat([perf_df_P, row_df], ignore_index = True)\n",
"\n",
"\n",
"print(perf_df_P.mean())\n",
"\n",
"perf_df_P\n"
]
},
{
"cell_type": "markdown",
"id": "dbb344e2",
"metadata": {},
"source": [
"Add to players data their mean vote (and its standard deviation).\n",
"\n",
"For players who don't have a minimum amount of games, more data to reach this value is computed, according to the average Serie A player vote (and std). For goalkeepers, this values are different.\n"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "c9312080",
"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>vote_avg</th>\n",
" <th>vote_std</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>5.833333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>7.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>6.166667</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6.217118</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>5.378980</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>5.558549</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>5.292137</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" vote_avg vote_std\n",
"0 6.000000 0.000000\n",
"1 5.833333 0.235702\n",
"2 6.000000 0.000000\n",
"3 7.000000 0.000000\n",
"4 6.166667 0.235702\n",
".. ... ...\n",
"530 6.217118 0.000000\n",
"531 6.000000 0.000000\n",
"532 5.378980 0.000000\n",
"533 5.558549 0.000000\n",
"534 5.292137 0.000000\n",
"\n",
"[535 rows x 2 columns]"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"min_votes = 1 # TO BE UPDATED WHEN SERIE A HAS MORE CALENDAR WEEKS PLAYED\n",
"\n",
"#outfield players\n",
"mean_def = 6\n",
"std_def = 0.58\n",
"\n",
"#goalkeepers\n",
"mean_def_P = 6.22\n",
"std_def_P = 0.43\n",
"\n",
"\n",
"perf_df = pd.DataFrame(columns = ['vote_avg', 'vote_std'])\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" v = np.array([])\n",
" for j in range(votes.shape[0]):\n",
" if(fc_players['name'][i] == votes['player'][j]):\n",
" v = np.append(v, votes['vote'][j])\n",
" \n",
" mean_def_i = mean_def\n",
" std_def_i = std_def\n",
" \n",
" if(fc_players['r'][i] == 'P'):\n",
" mean_def_i = mean_def_P\n",
" std_def_i = std_def_P\n",
" \n",
" if(v.shape[0] < min_votes):\n",
" for k in range(min_votes - v.shape[0]):\n",
" v = np.append( v, np.random.normal(mean_def_i, std_def_i) )\n",
" \n",
" row_df = pd.DataFrame(data = [[np.mean(v), np.std(v)]], columns = perf_df.columns)\n",
" perf_df = pd.concat([perf_df, row_df], ignore_index = True)\n",
" \n",
"perf_df\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "b2570ce5",
"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>id</th>\n",
" <th>r</th>\n",
" <th>name</th>\n",
" <th>team</th>\n",
" <th>surname</th>\n",
" <th>initial</th>\n",
" <th>fb_ID</th>\n",
" <th>age</th>\n",
" <th>birth_year</th>\n",
" <th>games</th>\n",
" <th>...</th>\n",
" <th>gk_pct_goal_kicks_launched</th>\n",
" <th>gk_goal_kick_length_avg</th>\n",
" <th>gk_crosses</th>\n",
" <th>gk_crosses_stopped</th>\n",
" <th>gk_crosses_stopped_pct</th>\n",
" <th>gk_def_actions_outside_pen_area</th>\n",
" <th>gk_def_actions_outside_pen_area_per90</th>\n",
" <th>gk_avg_distance_def_actions</th>\n",
" <th>vote_avg</th>\n",
" <th>vote_std</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4312</td>\n",
" <td>P</td>\n",
" <td>Maignan</td>\n",
" <td>Milan</td>\n",
" <td>Maignan</td>\n",
" <td></td>\n",
" <td>406</td>\n",
" <td>28-068</td>\n",
" <td>1995</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>65.0</td>\n",
" <td>49.3</td>\n",
" <td>43</td>\n",
" <td>12</td>\n",
" <td>27.9</td>\n",
" <td>3</td>\n",
" <td>1.00</td>\n",
" <td>10.3</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>572</td>\n",
" <td>P</td>\n",
" <td>Meret</td>\n",
" <td>Napoli</td>\n",
" <td>Meret</td>\n",
" <td></td>\n",
" <td>408</td>\n",
" <td>26-171</td>\n",
" <td>1997</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>21.4</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" <td>6.7</td>\n",
" <td>5</td>\n",
" <td>1.67</td>\n",
" <td>18.1</td>\n",
" <td>5.833333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2428</td>\n",
" <td>P</td>\n",
" <td>Sommer</td>\n",
" <td>Inter</td>\n",
" <td>Sommer</td>\n",
" <td></td>\n",
" <td>420</td>\n",
" <td>34-266</td>\n",
" <td>1988</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>23.8</td>\n",
" <td>31.0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>2.9</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>6.8</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>453</td>\n",
" <td>P</td>\n",
" <td>Szczesny</td>\n",
" <td>Juventus</td>\n",
" <td>Szczesny</td>\n",
" <td></td>\n",
" <td>421</td>\n",
" <td>33-144</td>\n",
" <td>1990</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>66.7</td>\n",
" <td>53.3</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>6.3</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>10.8</td>\n",
" <td>7.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2814</td>\n",
" <td>P</td>\n",
" <td>Provedel</td>\n",
" <td>Lazio</td>\n",
" <td>Provedel</td>\n",
" <td></td>\n",
" <td>416</td>\n",
" <td>29-176</td>\n",
" <td>1994</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>27.3</td>\n",
" <td>31.6</td>\n",
" <td>39</td>\n",
" <td>2</td>\n",
" <td>5.1</td>\n",
" <td>6</td>\n",
" <td>2.00</td>\n",
" <td>16.3</td>\n",
" <td>6.166667</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6242</td>\n",
" <td>A</td>\n",
" <td>Bidaoui</td>\n",
" <td>Frosinone</td>\n",
" <td>Bidaoui</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>6.217118</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6418</td>\n",
" <td>A</td>\n",
" <td>Burnete</td>\n",
" <td>Lecce</td>\n",
" <td>Burnete</td>\n",
" <td></td>\n",
" <td>51</td>\n",
" <td>19-221</td>\n",
" <td>2004</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>6419</td>\n",
" <td>A</td>\n",
" <td>Corfitzen</td>\n",
" <td>Lecce</td>\n",
" <td>Corfitzen</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.378980</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>6427</td>\n",
" <td>A</td>\n",
" <td>Stewart</td>\n",
" <td>Salernitana</td>\n",
" <td>Stewart</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.558549</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>6434</td>\n",
" <td>A</td>\n",
" <td>Yildiz</td>\n",
" <td>Juventus</td>\n",
" <td>Yildiz</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.292137</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 160 columns</p>\n",
"</div>"
],
"text/plain": [
" id r name team surname initial fb_ID age \\\n",
"0 4312 P Maignan Milan Maignan 406 28-068 \n",
"1 572 P Meret Napoli Meret 408 26-171 \n",
"2 2428 P Sommer Inter Sommer 420 34-266 \n",
"3 453 P Szczesny Juventus Szczesny 421 33-144 \n",
"4 2814 P Provedel Lazio Provedel 416 29-176 \n",
".. ... .. ... ... ... ... ... ... \n",
"530 6242 A Bidaoui Frosinone Bidaoui -1 0 \n",
"531 6418 A Burnete Lecce Burnete 51 19-221 \n",
"532 6419 A Corfitzen Lecce Corfitzen -1 0 \n",
"533 6427 A Stewart Salernitana Stewart -1 0 \n",
"534 6434 A Yildiz Juventus Yildiz -1 0 \n",
"\n",
" birth_year games ... gk_pct_goal_kicks_launched \\\n",
"0 1995 0 ... 65.0 \n",
"1 1997 0 ... 0.0 \n",
"2 1988 0 ... 23.8 \n",
"3 1990 0 ... 66.7 \n",
"4 1994 0 ... 27.3 \n",
".. ... ... ... ... \n",
"530 0 0 ... 0.0 \n",
"531 2004 1 ... 0.0 \n",
"532 0 0 ... 0.0 \n",
"533 0 0 ... 0.0 \n",
"534 0 0 ... 0.0 \n",
"\n",
" gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n",
"0 49.3 43 12 \n",
"1 21.4 15 1 \n",
"2 31.0 35 1 \n",
"3 53.3 16 1 \n",
"4 31.6 39 2 \n",
".. ... ... ... \n",
"530 0.0 0 0 \n",
"531 0.0 0 0 \n",
"532 0.0 0 0 \n",
"533 0.0 0 0 \n",
"534 0.0 0 0 \n",
"\n",
" gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n",
"0 27.9 3 \n",
"1 6.7 5 \n",
"2 2.9 0 \n",
"3 6.3 0 \n",
"4 5.1 6 \n",
".. ... ... \n",
"530 0.0 0 \n",
"531 0.0 0 \n",
"532 0.0 0 \n",
"533 0.0 0 \n",
"534 0.0 0 \n",
"\n",
" gk_def_actions_outside_pen_area_per90 gk_avg_distance_def_actions \\\n",
"0 1.00 10.3 \n",
"1 1.67 18.1 \n",
"2 0.00 6.8 \n",
"3 0.00 10.8 \n",
"4 2.00 16.3 \n",
".. ... ... \n",
"530 0.00 0.0 \n",
"531 0.00 0.0 \n",
"532 0.00 0.0 \n",
"533 0.00 0.0 \n",
"534 0.00 0.0 \n",
"\n",
" vote_avg vote_std \n",
"0 6.000000 0.000000 \n",
"1 5.833333 0.235702 \n",
"2 6.000000 0.000000 \n",
"3 7.000000 0.000000 \n",
"4 6.166667 0.235702 \n",
".. ... ... \n",
"530 6.217118 0.000000 \n",
"531 6.000000 0.000000 \n",
"532 5.378980 0.000000 \n",
"533 5.558549 0.000000 \n",
"534 5.292137 0.000000 \n",
"\n",
"[535 rows x 160 columns]"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc_players = pd.concat([fc_players, perf_df], axis = 1)\n",
"\n",
"fc_players"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "f7620abe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'gk_games'"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"GK_GAMES_COLUMN = 118\n",
"\n",
"fc_players.columns[GK_GAMES_COLUMN]\n",
"\n",
"# check it if is 'gk_games'"
]
},
{
"cell_type": "markdown",
"id": "c550c370",
"metadata": {},
"source": [
"For goalkeepers who didn't play a miminum amount of games, data is weightly averaged with one of the main goalkeeper of their same team."
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "700b7a7d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Carnesecchi, 0.0\n",
"Cragno, 0.0\n",
"Sportiello, 0.0\n",
"Mirante, 0.0\n",
"Sepe, 0.0\n",
"Leali, 0.0\n",
"Lamanna, 0.0\n",
"Sommariva, 0.0\n",
"Pegolo, 0.0\n",
"Perilli, 0.0\n",
"Padelli, 0.0\n",
"Scuffet, 0.0\n",
"Gollini, 0.0\n",
"Audero, 0.0\n",
"Di Gennaro, 0.0\n",
"Pinsoglio, 0.0\n",
"Aresti, 0.0\n",
"Fiorillo, 0.0\n",
"Rossi F., 0.0\n",
"Costil, 0.0\n",
"Ravaglia F., 0.0\n",
"Frattali, 0.0\n",
"Contini, 0.0\n",
"Brancolini, 0.0\n",
"Berardi A., 0.0\n",
"Gemello, 0.0\n",
"Boer, 0.0\n",
"Bagnolini, 0.0\n",
"Svilar, 0.0\n",
"Sorrentino A., 0.0\n",
"Martinelli T., 0.0\n",
"Popa, 0.0\n",
"Stubljar, 0.0\n",
"Gori, 0.0\n",
"Borbei, 0.0\n",
"Okoye, 0.0\n",
"Mandas, 0.0\n"
]
}
],
"source": [
"min_gk_games = 1 # TO BE UPDATED WHEN SERIE A HAS MORE CALENDAR WEEKS PLAYED\n",
"\n",
"fc_players_newgk = fc_players.copy()\n",
"\n",
"columns_to_avg = fc_players.columns[GK_GAMES_COLUMN:] # from gk_games to end\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" if(fc_players['r'][i] == 'P'):\n",
" if(fc_players['gk_games'][i] < min_gk_games):\n",
" for j in range(fc_players.shape[0]):\n",
" if(fc_players['team'][i] == fc_players['team'][j] and fc_players['gk_games'][j] >= min_gk_games):\n",
" break\n",
" \n",
" weight = 1 - (min_gk_games - fc_players['gk_games'][i]) / min_gk_games\n",
" \n",
" fc_players_newgk.at[i, columns_to_avg] = fc_players.loc[i][columns_to_avg] * weight + (1 - weight) * fc_players.loc[j][columns_to_avg]\n",
" \n",
" print(fc_players['name'][i] + ', ' + str(weight))\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "2d9eee99",
"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>id</th>\n",
" <th>r</th>\n",
" <th>name</th>\n",
" <th>team</th>\n",
" <th>surname</th>\n",
" <th>initial</th>\n",
" <th>fb_ID</th>\n",
" <th>age</th>\n",
" <th>birth_year</th>\n",
" <th>games</th>\n",
" <th>...</th>\n",
" <th>gk_pct_goal_kicks_launched</th>\n",
" <th>gk_goal_kick_length_avg</th>\n",
" <th>gk_crosses</th>\n",
" <th>gk_crosses_stopped</th>\n",
" <th>gk_crosses_stopped_pct</th>\n",
" <th>gk_def_actions_outside_pen_area</th>\n",
" <th>gk_def_actions_outside_pen_area_per90</th>\n",
" <th>gk_avg_distance_def_actions</th>\n",
" <th>vote_avg</th>\n",
" <th>vote_std</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>4312</td>\n",
" <td>P</td>\n",
" <td>Maignan</td>\n",
" <td>Milan</td>\n",
" <td>Maignan</td>\n",
" <td></td>\n",
" <td>406</td>\n",
" <td>28-068</td>\n",
" <td>1995</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>65.0</td>\n",
" <td>49.3</td>\n",
" <td>43</td>\n",
" <td>12</td>\n",
" <td>27.9</td>\n",
" <td>3</td>\n",
" <td>1.00</td>\n",
" <td>10.3</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>572</td>\n",
" <td>P</td>\n",
" <td>Meret</td>\n",
" <td>Napoli</td>\n",
" <td>Meret</td>\n",
" <td></td>\n",
" <td>408</td>\n",
" <td>26-171</td>\n",
" <td>1997</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>21.4</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" <td>6.7</td>\n",
" <td>5</td>\n",
" <td>1.67</td>\n",
" <td>18.1</td>\n",
" <td>5.833333</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2428</td>\n",
" <td>P</td>\n",
" <td>Sommer</td>\n",
" <td>Inter</td>\n",
" <td>Sommer</td>\n",
" <td></td>\n",
" <td>420</td>\n",
" <td>34-266</td>\n",
" <td>1988</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>23.8</td>\n",
" <td>31.0</td>\n",
" <td>35</td>\n",
" <td>1</td>\n",
" <td>2.9</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>6.8</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>453</td>\n",
" <td>P</td>\n",
" <td>Szczesny</td>\n",
" <td>Juventus</td>\n",
" <td>Szczesny</td>\n",
" <td></td>\n",
" <td>421</td>\n",
" <td>33-144</td>\n",
" <td>1990</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>66.7</td>\n",
" <td>53.3</td>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>6.3</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>10.8</td>\n",
" <td>7.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2814</td>\n",
" <td>P</td>\n",
" <td>Provedel</td>\n",
" <td>Lazio</td>\n",
" <td>Provedel</td>\n",
" <td></td>\n",
" <td>416</td>\n",
" <td>29-176</td>\n",
" <td>1994</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>27.3</td>\n",
" <td>31.6</td>\n",
" <td>39</td>\n",
" <td>2</td>\n",
" <td>5.1</td>\n",
" <td>6</td>\n",
" <td>2.00</td>\n",
" <td>16.3</td>\n",
" <td>6.166667</td>\n",
" <td>0.235702</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>530</th>\n",
" <td>6242</td>\n",
" <td>A</td>\n",
" <td>Bidaoui</td>\n",
" <td>Frosinone</td>\n",
" <td>Bidaoui</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>6.217118</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>531</th>\n",
" <td>6418</td>\n",
" <td>A</td>\n",
" <td>Burnete</td>\n",
" <td>Lecce</td>\n",
" <td>Burnete</td>\n",
" <td></td>\n",
" <td>51</td>\n",
" <td>19-221</td>\n",
" <td>2004</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>6.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>532</th>\n",
" <td>6419</td>\n",
" <td>A</td>\n",
" <td>Corfitzen</td>\n",
" <td>Lecce</td>\n",
" <td>Corfitzen</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.378980</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>533</th>\n",
" <td>6427</td>\n",
" <td>A</td>\n",
" <td>Stewart</td>\n",
" <td>Salernitana</td>\n",
" <td>Stewart</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.558549</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>534</th>\n",
" <td>6434</td>\n",
" <td>A</td>\n",
" <td>Yildiz</td>\n",
" <td>Juventus</td>\n",
" <td>Yildiz</td>\n",
" <td></td>\n",
" <td>-1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>0.00</td>\n",
" <td>0.0</td>\n",
" <td>5.292137</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>535 rows × 160 columns</p>\n",
"</div>"
],
"text/plain": [
" id r name team surname initial fb_ID age \\\n",
"0 4312 P Maignan Milan Maignan 406 28-068 \n",
"1 572 P Meret Napoli Meret 408 26-171 \n",
"2 2428 P Sommer Inter Sommer 420 34-266 \n",
"3 453 P Szczesny Juventus Szczesny 421 33-144 \n",
"4 2814 P Provedel Lazio Provedel 416 29-176 \n",
".. ... .. ... ... ... ... ... ... \n",
"530 6242 A Bidaoui Frosinone Bidaoui -1 0 \n",
"531 6418 A Burnete Lecce Burnete 51 19-221 \n",
"532 6419 A Corfitzen Lecce Corfitzen -1 0 \n",
"533 6427 A Stewart Salernitana Stewart -1 0 \n",
"534 6434 A Yildiz Juventus Yildiz -1 0 \n",
"\n",
" birth_year games ... gk_pct_goal_kicks_launched \\\n",
"0 1995 0 ... 65.0 \n",
"1 1997 0 ... 0.0 \n",
"2 1988 0 ... 23.8 \n",
"3 1990 0 ... 66.7 \n",
"4 1994 0 ... 27.3 \n",
".. ... ... ... ... \n",
"530 0 0 ... 0.0 \n",
"531 2004 1 ... 0.0 \n",
"532 0 0 ... 0.0 \n",
"533 0 0 ... 0.0 \n",
"534 0 0 ... 0.0 \n",
"\n",
" gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n",
"0 49.3 43 12 \n",
"1 21.4 15 1 \n",
"2 31.0 35 1 \n",
"3 53.3 16 1 \n",
"4 31.6 39 2 \n",
".. ... ... ... \n",
"530 0.0 0 0 \n",
"531 0.0 0 0 \n",
"532 0.0 0 0 \n",
"533 0.0 0 0 \n",
"534 0.0 0 0 \n",
"\n",
" gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n",
"0 27.9 3 \n",
"1 6.7 5 \n",
"2 2.9 0 \n",
"3 6.3 0 \n",
"4 5.1 6 \n",
".. ... ... \n",
"530 0.0 0 \n",
"531 0.0 0 \n",
"532 0.0 0 \n",
"533 0.0 0 \n",
"534 0.0 0 \n",
"\n",
" gk_def_actions_outside_pen_area_per90 gk_avg_distance_def_actions \\\n",
"0 1.00 10.3 \n",
"1 1.67 18.1 \n",
"2 0.00 6.8 \n",
"3 0.00 10.8 \n",
"4 2.00 16.3 \n",
".. ... ... \n",
"530 0.00 0.0 \n",
"531 0.00 0.0 \n",
"532 0.00 0.0 \n",
"533 0.00 0.0 \n",
"534 0.00 0.0 \n",
"\n",
" vote_avg vote_std \n",
"0 6.000000 0.000000 \n",
"1 5.833333 0.235702 \n",
"2 6.000000 0.000000 \n",
"3 7.000000 0.000000 \n",
"4 6.166667 0.235702 \n",
".. ... ... \n",
"530 6.217118 0.000000 \n",
"531 6.000000 0.000000 \n",
"532 5.378980 0.000000 \n",
"533 5.558549 0.000000 \n",
"534 5.292137 0.000000 \n",
"\n",
"[535 rows x 160 columns]"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc_players = fc_players_newgk\n",
"\n",
"fc_players"
]
},
{
"cell_type": "markdown",
"id": "2b13240e",
"metadata": {},
"source": [
"Save to file."
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "8336c025",
"metadata": {},
"outputs": [],
"source": [
"fc_players.to_excel('mid_outputs/players_stats.xlsx')"
]
}
],
"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
}