{
"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": 1,
"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": 2,
"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": 3,
"id": "667970f6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" player | \n",
" team | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" James Abankwah | \n",
" Udinese | \n",
"
\n",
" \n",
" | 1 | \n",
" Oliver Abildgaard | \n",
" Hellas Verona | \n",
"
\n",
" \n",
" | 2 | \n",
" Tammy Abraham | \n",
" Roma | \n",
"
\n",
" \n",
" | 3 | \n",
" Christian Acella | \n",
" Cremonese | \n",
"
\n",
" \n",
" | 4 | \n",
" Francesco Acerbi | \n",
" Inter | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 617 | \n",
" Pietro Terracciano | \n",
" Fiorentina | \n",
"
\n",
" \n",
" | 618 | \n",
" Martin Turk | \n",
" Sampdoria | \n",
"
\n",
" \n",
" | 619 | \n",
" Guglielmo Vicario | \n",
" Empoli | \n",
"
\n",
" \n",
" | 620 | \n",
" Jeroen Zoet | \n",
" Spezia | \n",
"
\n",
" \n",
" | 621 | \n",
" Petar Zovko | \n",
" Spezia | \n",
"
\n",
" \n",
"
\n",
"
622 rows × 2 columns
\n",
"
"
],
"text/plain": [
" player team\n",
"0 James Abankwah Udinese\n",
"1 Oliver Abildgaard Hellas Verona\n",
"2 Tammy Abraham Roma\n",
"3 Christian Acella Cremonese\n",
"4 Francesco Acerbi Inter\n",
".. ... ...\n",
"617 Pietro Terracciano Fiorentina\n",
"618 Martin Turk Sampdoria\n",
"619 Guglielmo Vicario Empoli\n",
"620 Jeroen Zoet Spezia\n",
"621 Petar Zovko Spezia\n",
"\n",
"[622 rows x 2 columns]"
]
},
"execution_count": 3,
"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": 4,
"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": 5,
"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": 6,
"id": "ffd6091c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" player surname\n",
"0 James Abankwah Abankwah\n",
"1 Oliver Abildgaard Abildgaard\n",
"2 Tammy Abraham Abraham\n",
"3 Christian Acella Acella\n",
"4 Francesco Acerbi Acerbi\n",
"5 Yacine Adli Adli\n",
"6 Michel Aebischer Aebischer\n",
"7 Felix Afena-Gyan Afena-Gyan\n",
"8 Kevin Agudelo Agudelo\n",
"9 Ola Aina Aina\n",
"10 Emanuel Aiwum Aiwum\n",
"11 Jean-Daniel Akpa-Akpro Akpa-Akpro\n",
"12 Luis Alberto Alberto\n",
"13 Agustín Álvarez Martínez Martinez\n",
"14 Kelvin Amian Amian\n",
"15 Bruno Amione Amione\n",
"16 Bruno Amione Amione\n",
"17 Ethan Ampadu Ampadu\n",
"18 Sofyan Amrabat Amrabat\n",
"19 Felipe Anderson Anderson\n",
"20 Janis Antiste Antiste\n",
"21 Marcos Antônio Antonio\n",
"22 Valentin Antov Antov\n",
"23 Marko Arnautović Arnautovic\n",
"24 Tolgay Arslan Arslan\n",
"25 Arthur Arthur\n",
"26 Santiago Ascacíbar Ascacibar\n",
"27 Kristoffer Askildsen Askildsen\n",
"28 Kristjan Asllani Asllani\n",
"29 Emil Audero Audero\n",
"30 Tommaso Augello Augello\n",
"31 Kaan Ayhan Ayhan\n",
"32 Jaime Báez Baez\n",
"33 Nedim Bajrami Bajrami\n",
"34 Nedim Bajrami Bajrami\n",
"35 Tiemoué Bakayoko Bakayoko\n",
"36 Tommaso Baldanzi Baldanzi\n",
"37 Fodé Ballo-Touré Ballo-Toure\n",
"38 Lameck Banda Banda\n",
"39 Filippo Bandinelli Bandinelli\n",
"40 Antonín Barák Barak\n",
"41 Antonín Barák Barak\n",
"42 Andrea Barberis Barberis\n",
"43 Tommaso Barbieri Barbieri\n",
"44 Francesco Bardi Bardi\n",
"45 Nicolò Barella Barella\n",
"46 Enzo Barrenechea Barrenechea\n",
"47 Musa Barrow Barrow\n",
"48 Federico Baschirotto Baschirotto\n",
"49 Toma Bašić Basic\n",
"50 Alberto Basso Basso\n",
"51 Alessandro Bastoni Bastoni\n",
"52 Simone Bastoni Bastoni\n",
"53 Brian Bayeye Bayeye\n",
"54 Rodrigo Becão Becao\n",
"55 Julius Beck Beck\n",
"56 Raoul Bellanova Bellanova\n",
"57 Andrea Belotti Belotti\n",
"58 Marco Benassi Benassi\n",
"59 Marco Benassi Benassi\n",
"60 Ismaël Bennacer Bennacer\n",
"61 Domenico Berardi Berardi\n",
"62 Bartosz Bereszyński Bereszynski\n",
"63 Beto Beto\n",
"64 Matteo Bianchetti Bianchetti\n",
"65 Alessandro Bianco Bianco\n",
"66 Jaka Bijol Bijol\n",
"67 Cristiano Biraghi Biraghi\n",
"68 Samuele Birindelli Birindelli\n",
"69 Kristijan Bistrović Bistrovic\n",
"70 Alexis Blin Blin\n",
"71 Jeremie Boga Boga\n",
"72 Emil Bohinen Bohinen\n",
"73 Giacomo Bonaventura Bonaventura\n",
"74 Federico Bonazzoli Bonazzoli\n",
"75 Warren Bondo Bondo\n",
"76 Kevin Bonifazi Bonifazi\n",
"77 Leonardo Bonucci Bonucci\n",
"78 Erik Botheim Botheim\n",
"79 Mehdi Bourabia Bourabia\n",
"80 Edoardo Bove Bove\n",
"81 Jayden Braaf Braaf\n",
"82 Domagoj Bradarić Bradaric\n",
"83 Josip Brekalo Brekalo\n",
"84 Gleison Bremer Bremer\n",
"85 Dylan Bronn Bronn\n",
"86 Marcelo Brozović Brozovic\n",
"87 Cristian Buonaiuto Buonaiuto\n",
"88 Alessandro Buongiorno Buongiorno\n",
"89 Juan Cabal Cabal\n",
"90 Liberato Cacace Cacace\n",
"91 Davide Calabria Calabria\n",
"92 Mattia Caldara Caldara\n",
"93 Luca Caldirola Caldirola\n",
"94 Hakan Çalhanoğlu Calhanoglu\n",
"95 Mohamed Camara Camara\n",
"96 Nicolò Cambiaghi Cambiaghi\n",
"97 Andrea Cambiaso Cambiaso\n",
"98 Matteo Cancellieri Cancellieri\n",
"99 Antonio Candreva Candreva\n",
"100 Gianluca Caprari Caprari\n",
"101 Francesco Caputo Caputo\n",
"102 Francesco Caputo Caputo\n",
"103 Andrea Carboni Carboni\n",
"104 Franco Carboni Carboni\n",
"105 Valentin Carboni Carboni\n",
"106 Carlos Carlos\n",
"107 Marco Carnesecchi Carnesecchi\n",
"108 Nicolò Casale Casale\n",
"109 Tommaso Cassandro Cassandro\n",
"110 Michele Castagnetti Castagnetti\n",
"111 Gaetano Castrovilli Castrovilli\n",
"112 Danilo Cataldi Cataldi\n",
"113 Pietro Ceccaroni Ceccaroni\n",
"114 Federico Ceccherini Ceccherini\n",
"115 Assan Ceesay Ceesay\n",
"116 Emil Ceide Ceide\n",
"117 Zeki Çelik Celik\n",
"118 Michele Cerofolini Cerofolini\n",
"119 Federico Chiesa Chiesa\n",
"120 Vlad Chiricheș Chiriches\n",
"121 Daniel Ciofani Ciofani\n",
"122 Tio Cipot Cipot\n",
"123 Patrick Ciurria Ciurria\n",
"124 Omar Colley Colley\n",
"125 Lorenzo Colombo Colombo\n",
"126 Andrea Colpani Colpani\n",
"127 Andrea Consigli Consigli\n",
"128 Andrea Conti Conti\n",
"129 Diego Coppola Coppola\n",
"130 Joaquín Correa Correa\n",
"131 Alessandro Cortinovis Cortinovis\n",
"132 Lassana Coulibaly Coulibaly\n",
"133 Alessio Cragno Cragno\n",
"134 Bryan Cristante Cristante\n",
"135 Domen Črnigoj Crnigoj\n",
"136 Juan Cuadrado Cuadrado\n",
"137 Mickaël Cuisance Cuisance\n",
"138 Marco D'Alessandro DAlessandro\n",
"139 Danilo D'Ambrosio DAmbrosio\n",
"140 Luca D'Andrea DAndrea\n",
"141 Flavius Daniliuc Daniliuc\n",
"142 Danilo Danilo\n",
"143 Matteo Darmian Darmian\n",
"144 Paweł Dawidowicz Dawidowicz\n",
"145 Charles De Ketelaere Ketelaere\n",
"146 Manuel De Luca Luca\n",
"147 Mattia De Sciglio Sciglio\n",
"148 Lorenzo De Silvestri Silvestri\n",
"149 Koni De Winter Winter\n",
"150 Grégoire Defrel Defrel\n",
"151 Duccio Degl'Innocenti DeglInnocenti\n",
"152 Merih Demiral Demiral\n",
"153 Diego Demme Demme\n",
"154 Fabio Depaoli Depaoli\n",
"155 Fabio Depaoli Depaoli\n",
"156 Kastriot Dermaku Dermaku\n",
"157 Cyriel Dessers Dessers\n",
"158 Sergiño Dest Dest\n",
"159 Mattia Destro Destro\n",
"160 Gerard Deulofeu Deulofeu\n",
"161 Samuel Di Carmine Carmine\n",
"162 Federico Di Francesco Francesco\n",
"163 Michele Di Gregorio Gregorio\n",
"164 Giovanni Di Lorenzo Lorenzo\n",
"165 Ángel Di María Maria\n",
"166 Boulaye Dia Dia\n",
"167 Brahim Díaz Diaz\n",
"168 Federico Dimarco Dimarco\n",
"169 Koffi Djidji Djidji\n",
"170 Berat Djimsiti Djimsiti\n",
"171 Dodô Dodo\n",
"172 Josh Doig Doig\n",
"173 Nicolás Domínguez Dominguez\n",
"174 Giulio Donati Donati\n",
"175 Bartłomiej Drągowski Dragowski\n",
"176 Ondrej Duda Duda\n",
"177 Denzel Dumfries Dumfries\n",
"178 Alfred Duncan Duncan\n",
"179 Paulo Dybala Dybala\n",
"180 Edin Džeko Dzeko\n",
"181 Festy Ebosele Ebosele\n",
"182 Enzo Ebosse Ebosse\n",
"183 Tyronne Ebuehi Ebuehi\n",
"184 Éderson Ederson\n",
"185 Kingsley Ehizibue Ehizibue\n",
"186 Albin Ekdal Ekdal\n",
"187 Emmanuel Ekong Ekong\n",
"188 Mikael Ellertsson Ellertsson\n",
"189 Elif Elmas Elmas\n",
"190 Martin Erlic Erlic\n",
"191 Gonzalo Escalante Escalante\n",
"192 Salvatore Esposito Esposito\n",
"193 Nicolò Fagioli Fagioli\n",
"194 Wladimiro Falcone Falcone\n",
"195 Davide Faraoni Faraoni\n",
"196 Federico Fazio Fazio\n",
"197 Jacopo Fazzini Fazzini\n",
"198 Lewis Ferguson Ferguson\n",
"199 Alex Ferrari Ferrari\n",
"200 Alex Ferrari Ferrari\n",
"201 Salvador Ferrer Ferrer\n",
"202 Alessandro Florenzi Florenzi\n",
"203 Davide Frattesi Frattesi\n",
"204 Matteo Gabbia Gabbia\n",
"205 Manolo Gabbiadini Gabbiadini\n",
"206 Gianluca Gaetano Gaetano\n",
"207 Roberto Gagliardini Gagliardini\n",
"208 Adolfo Gaich Gaich\n",
"209 Pablo Galdames Millán Millan\n",
"210 Antonino Gallo Gallo\n",
"211 Federico Gatti Gatti\n",
"212 Valentin Gendrey Gendrey\n",
"213 Paolo Ghiglione Ghiglione\n",
"214 Mario Gila Gila\n",
"215 Gvidas Gineitis Gineitis\n",
"216 Olivier Giroud Giroud\n",
"217 Pierluigi Gollini Gollini\n",
"218 Pierluigi Gollini Gollini\n",
"219 Joan Gonzàlez Gonzalez\n",
"220 Nicolás González Gonzalez\n",
"221 Robin Gosens Gosens\n",
"222 Alberto Grassi Grassi\n",
"223 Andrew Gravillon Gravillon\n",
"224 Koray Günter Gunter\n",
"225 Koray Günter Gunter\n",
"226 Emmanuel Gyasi Gyasi\n",
"227 Norbert Gyömbér Gyomber\n",
"228 Christian Gytkjær Gytkjr\n",
"229 Nicolas Haas Haas\n",
"230 Samir Handanović Handanovic\n",
"231 Abdou Harroui Harroui\n",
"232 Hans Hateboer Hateboer\n",
"233 Liam Henderson Henderson\n",
"234 Jack Hendry Hendry\n",
"235 Matheus Henrique Henrique\n",
"236 Thomas Henry Henry\n",
"237 Theo Hernández Hernandez\n",
"238 Isak Hien Hien\n",
"239 Morten Hjulmand Hjulmand\n",
"240 Emil Holm Holm\n",
"241 Martin Hongla Hongla\n",
"242 Petko Hristov Hristov\n",
"243 Ajdin Hrustic Hrustic\n",
"244 Elseid Hysaj Hysaj\n",
"245 Rasmus Højlund Hjlund\n",
"246 Roger Ibanez Ibanez\n",
"247 Zlatan Ibrahimović Ibrahimovic\n",
"248 Igor Igor\n",
"249 Jonathan Ikone Ikone\n",
"250 Ivan Ilić Ilic\n",
"251 Ivan Ilić Ilic\n",
"252 Samuel Iling-Junior Iling-Junior\n",
"253 Emirhan İlkhan Ilkhan\n",
"254 Emirhan İlkhan Ilkhan\n",
"255 Ciro Immobile Immobile\n",
"256 Ardian Ismajli Ismajli\n",
"257 Armando Izzo Izzo\n",
"258 Mato Jajalo Jajalo\n",
"259 Jesé Jese\n",
"260 Juan Jesus Jesus\n",
"261 Þórir Jóhann Helgason Helgason\n",
"262 Luka Jović Jovic\n",
"263 Hamed Junior Traorè Traore\n",
"264 Yayah Kallon Kallon\n",
"265 Pierre Kalulu Kalulu\n",
"266 Yann Karamoh Karamoh\n",
"267 Rick Karsdorp Karsdorp\n",
"268 Denso Kasius Kasius\n",
"269 Grigoris Kastanos Kastanos\n",
"270 Moise Kean Kean\n",
"271 Jakub Kiwior Kiwior\n",
"272 Simon Kjær Kjr\n",
"273 Teun Koopmeiners Koopmeiners\n",
"274 Filip Kostić Kostic\n",
"275 Christian Kouamé Kouame\n",
"276 Viktor Kovalenko Kovalenko\n",
"277 Julian Kristoffersen Kristoffersen\n",
"278 Raimonds Krollis Krollis\n",
"279 Rade Krunić Krunic\n",
"280 Marash Kumbulla Kumbulla\n",
"281 Khvicha Kvaratskhelia Kvaratskhelia\n",
"282 Giorgos Kyriakopoulos Kyriakopoulos\n",
"283 Giorgos Kyriakopoulos Kyriakopoulos\n",
"284 Sam Lammers Lammers\n",
"285 Sam Lammers Lammers\n",
"286 Kevin Lasagna Lasagna\n",
"287 Armand Lauriente Lauriente\n",
"288 Valentino Lazaro Lazaro\n",
"289 Marko Lazetić Lazetic\n",
"290 Darko Lazović Lazovic\n",
"291 Manuel Lazzari Lazzari\n",
"292 Rafael Leão Leao\n",
"293 Mehdi Léris Leris\n",
"294 Karol Linetty Linetty\n",
"295 Marcin Listkowski Listkowski\n",
"296 Diego Llorente Llorente\n",
"297 Stanislav Lobotka Lobotka\n",
"298 Manuel Locatelli Locatelli\n",
"299 Luka Lochoshvili Lochoshvili\n",
"300 Ademola Lookman Lookman\n",
"301 Maxime Lopez Lopez\n",
"302 Matteo Lovato Lovato\n",
"303 Sandi Lovrić Lovric\n",
"304 Hirving Lozano Lozano\n",
"305 Jhon Lucumí Lucumi\n",
"306 José Luis Palomino Palomino\n",
"307 Romelu Lukaku Lukaku\n",
"308 Saša Lukić Lukic\n",
"309 Sebastiano Luperto Luperto\n",
"310 Charalambos Lykogiannis Lykogiannis\n",
"311 Giulio Maggiore Maggiore\n",
"312 Giangiacomo Magnani Magnani\n",
"313 Mike Maignan Maignan\n",
"314 Jordan Majchrzak Majchrzak\n",
"315 Jean-Victor Makengo Makengo\n",
"316 Lorenzo Malagrida Malagrida\n",
"317 Daniel Maldini Maldini\n",
"318 Youssef Maleh Maleh\n",
"319 Youssef Maleh Maleh\n",
"320 Ruslan Malinovskyi Malinovskyi\n",
"321 Gianluca Mancini Mancini\n",
"322 Rolando Mandragora Mandragora\n",
"323 Federico Marchetti Marchetti\n",
"324 Riccardo Marchizza Marchizza\n",
"325 Gian Marco Ferrari Ferrari\n",
"326 Pablo Marí Mari\n",
"327 Răzvan Marin Marin\n",
"328 Marlon Marlon\n",
"329 Luca Marrone Marrone\n",
"330 Lautaro Martínez Martinez\n",
"331 Lucas Martínez Quarta Quarta\n",
"332 Adam Marušić Marusic\n",
"333 Adam Masina Masina\n",
"334 Nemanja Matić Matic\n",
"335 Luís Maximiano Maximiano\n",
"336 Pasquale Mazzocchi Mazzocchi\n",
"337 Weston McKennie McKennie\n",
"338 Gary Medel Medel\n",
"339 Soualiho Meïté Meite\n",
"340 Alex Meret Meret\n",
"341 Yıldırım Mert Çetin Cetin\n",
"342 Junior Messias Messias\n",
"343 Tommaso Milanese Milanese\n",
"344 Nikola Milenković Milenkovic\n",
"345 Arkadiusz Milik Milik\n",
"346 Sergej Milinković-Savić Milinkovic-Savic\n",
"347 Vanja Milinković-Savić Milinkovic-Savic\n",
"348 Kim Min-jae Min-jae\n",
"349 Aleksei Miranchuk Miranchuk\n",
"350 Fabio Miretti Miretti\n",
"351 Henrikh Mkhitaryan Mkhitaryan\n",
"352 Salvatore Molina Molina\n",
"353 Daniele Montevago Montevago\n",
"354 Lorenzo Montipò Montipo\n",
"355 Nikola Moro Moro\n",
"356 Dany Mota Mota\n",
"357 João Moutinho Moutinho\n",
"358 Mert Müldür Muldur\n",
"359 Luis Muriel Muriel\n",
"360 Jeison Murillo Murillo\n",
"361 Nicola Murru Murru\n",
"362 Juan Musso Musso\n",
"363 Joakim Mæhle Mhle\n",
"364 Herculano Nabian Nabian\n",
"365 Michel Ndary Adopo Adopo\n",
"366 Tanguy Ndombele Ndombele\n",
"367 Ilija Nestorovski Nestorovski\n",
"368 Cyril Ngonge Ngonge\n",
"369 Hans Nicolussi Caviglia Caviglia\n",
"370 Dimitris Nikolaou Nikolaou\n",
"371 Bram Nuytinck Nuytinck\n",
"372 Bram Nuytinck Nuytinck\n",
"373 M'Bala Nzola Nzola\n",
"374 Pedro Obiang Obiang\n",
"375 Guillermo Ochoa Ochoa\n",
"376 Marios Oikonomou Oikonomou\n",
"377 David Okereke Okereke\n",
"378 Caleb Okoli Okoli\n",
"379 Mathías Olivera Olivera\n",
"380 André Onana Onana\n",
"381 Divock Origi Origi\n",
"382 Riccardo Orsolini Orsolini\n",
"383 Victor Osimhen Osimhen\n",
"384 Remi Oudin Oudin\n",
"385 Adam Ounas Ounas\n",
"386 Simone Pafundi Pafundi\n",
"387 Flavio Paoletti Paoletti\n",
"388 Leandro Paredes Paredes\n",
"389 Fabiano Parisi Parisi\n",
"390 Mario Pašalić Pasalic\n",
"391 Patric Patric\n",
"392 Rui Patrício Patricio\n",
"393 Pedro Pedro\n",
"394 Gianluca Pegolo Pegolo\n",
"395 Pietro Pellegri Pellegri\n",
"396 Lorenzo Pellegrini Pellegrini\n",
"397 Luca Pellegrini Pellegrini\n",
"398 Pepín Pepin\n",
"399 Roberto Pereyra Pereyra\n",
"400 Nehuén Pérez Perez\n",
"401 Simone Perilli Perilli\n",
"402 Mattia Perin Perin\n",
"403 Samuele Perisan Perisan\n",
"404 Matteo Pessina Pessina\n",
"405 Andrea Petagna Petagna\n",
"406 Giuseppe Pezzella Pezzella\n",
"407 Krzysztof Piątek Piatek\n",
"408 Roberto Piccoli Piccoli\n",
"409 Roberto Piccoli Piccoli\n",
"410 Charles Pickel Pickel\n",
"411 Andrea Pinamonti Pinamonti\n",
"412 Lorenzo Pirola Pirola\n",
"413 Marko Pjaca Pjaca\n",
"414 Tommaso Pobega Pobega\n",
"415 Paul Pogba Pogba\n",
"416 Matteo Politano Politano\n",
"417 Marin Pongračić Pongracic\n",
"418 Stefan Posch Posch\n",
"419 Ivan Provedel Provedel\n",
"420 Ignacio Pussetto Pussetto\n",
"421 Niklas Pyyhtiä Pyyhtia\n",
"422 Fabio Quagliarella Quagliarella\n",
"423 Giacomo Quagliata Quagliata\n",
"424 Adrien Rabiot Rabiot\n",
"425 Nemanja Radonjić Radonjic\n",
"426 Ivan Radovanović Radovanovic\n",
"427 Ionuț Radu Radu\n",
"428 Antonio Raimondo Raimondo\n",
"429 Luca Ranieri Ranieri\n",
"430 Andrea Ranocchia Ranocchia\n",
"431 Filippo Ranocchia Ranocchia\n",
"432 Giacomo Raspadori Raspadori\n",
"433 Giacomo Raspadori Raspadori\n",
"434 Nicola Ravaglia Ravaglia\n",
"435 Ante Rebić Rebic\n",
"436 Arkadiusz Reca Reca\n",
"437 Panagiotis Retsos Retsos\n",
"438 Franck Ribéry Ribery\n",
"439 Samuele Ricci Ricci\n",
"440 Tomás Rincón Rincon\n",
"441 Pablo Rodríguez Rodriguez\n",
"442 Ricardo Rodríguez Rodriguez\n",
"443 Rogério Rogerio\n",
"444 Alessio Romagnoli Romagnoli\n",
"445 Simone Romagnoli Romagnoli\n",
"446 Luka Romero Romero\n",
"447 Marten de Roon Roon\n",
"448 Nicolò Rovella Rovella\n",
"449 Nicolò Rovella Rovella\n",
"450 Amir Rrahmani Rrahmani\n",
"451 Ruan Ruan\n",
"452 Daniele Rugani Rugani\n",
"453 Matteo Ruggeri Ruggeri\n",
"454 Mário Rui Rui\n",
"455 Abdelhamid Sabiri Sabiri\n",
"456 Alexis Saelemaekers Saelemaekers\n",
"457 Jacopo Sala Sala\n",
"458 Lazar Samardzic Samardzic\n",
"459 Junior Sambia Sambia\n",
"460 Antonio Sanabria Sanabria\n",
"461 Leandro Sanca Sanca\n",
"462 Alex Sandro Sandro\n",
"463 Nicola Sansone Sansone\n",
"464 Riccardo Saponara Saponara\n",
"465 Martin Satriano Satriano\n",
"466 Giorgio Scalvini Scalvini\n",
"467 Jerdy Schouten Schouten\n",
"468 Perr Schuurs Schuurs\n",
"469 Demba Seck Seck\n",
"470 Jacopo Segre Segre\n",
"471 Vivaldo Semedo Semedo\n",
"472 Stefano Sensi Sensi\n",
"473 Luigi Sepe Sepe\n",
"474 Leonardo Sernicola Sernicola\n",
"475 Stephan El Shaarawy Shaarawy\n",
"476 Eldor Shomurodov Shomurodov\n",
"477 Eldor Shomurodov Shomurodov\n",
"478 Marco Silvestri Silvestri\n",
"479 Giovanni Simeone Simeone\n",
"480 Wilfried Singo Singo\n",
"481 Salvatore Sirigu Sirigu\n",
"482 Leo Skiri Østigård stigard\n",
"483 Łukasz Skorupski Skorupski\n",
"484 Milan Škriniar Skriniar\n",
"485 Chris Smalling Smalling\n",
"486 Ola Solbakken Solbakken\n",
"487 Brandon Soppy Soppy\n",
"488 Brandon Soppy Soppy\n",
"489 Roberto Soriano Soriano\n",
"490 Joaquin Sosa Sosa\n",
"491 Riccardo Sottil Sottil\n",
"492 Matìas Soulé Soule\n",
"493 Adama Soumaoro Soumaoro\n",
"494 Leonardo Spinazzola Spinazzola\n",
"495 Marco Sportiello Sportiello\n",
"496 Petar Stojanović Stojanovic\n",
"497 Gabriel Strefezza Strefezza\n",
"498 Dávid Strelec Strelec\n",
"499 Isaac Success Success\n",
"500 Ibrahim Sulemana Sulemana\n",
"501 Wojciech Szczęsny Szczesny\n",
"502 Benjamin Tahirovic Tahirovic\n",
"503 Adrien Tameze Tameze\n",
"504 Ciprian Tătărușanu Tatarusanu\n",
"505 Filippo Terracciano Terracciano\n",
"506 Pietro Terracciano Terracciano\n",
"507 Aleksa Terzić Terzic\n",
"508 Florian Thauvin Thauvin\n",
"509 Malick Thiaw Thiaw\n",
"510 Kristian Thorstvedt Thorstvedt\n",
"511 Jeremy Toljan Toljan\n",
"512 Rafael Tolói Toloi\n",
"513 Fikayo Tomori Tomori\n",
"514 Sandro Tonali Tonali\n",
"515 Lorenzo Tonelli Tonelli\n",
"516 William Troost-Ekong Troost-Ekong\n",
"517 Frank Tsadjout Tsadjout\n",
"518 Alessandro Tuia Tuia\n",
"519 Martin Turk Turk\n",
"520 Iyenoma Udogie Udogie\n",
"521 Samuel Umtiti Umtiti\n",
"522 Diego Valencia Valencia\n",
"523 Emanuele Valeri Valeri\n",
"524 Mattia Valoti Valoti\n",
"525 Johan Vásquez Vasquez\n",
"526 Matías Vecino Vecino\n",
"527 Miguel Veloso Veloso\n",
"528 Lorenzo Venuti Venuti\n",
"529 Daniele Verde Verde\n",
"530 Simone Verdi Verdi\n",
"531 Valerio Verre Verre\n",
"532 Guglielmo Vicario Vicario\n",
"533 Ronaldo Vieira Vieira\n",
"534 Ronaldo Vieira Vieira\n",
"535 Emanuel Vignato Vignato\n",
"536 Emanuel Vignato Vignato\n",
"537 Samuele Vignato Vignato\n",
"538 Tonny Vilhena Vilhena\n",
"539 Gonzalo Villar Villar\n",
"540 Matías Viña Vina\n",
"541 Dušan Vlahović Vlahovic\n",
"542 Nikola Vlašić Vlasic\n",
"543 Joel Voelkerling Persson Persson\n",
"544 Mërgim Vojvoda Vojvoda\n",
"545 Cristian Volpato Volpato\n",
"546 Lukáš Vorlický Vorlicky\n",
"547 Aster Vranckx Vranckx\n",
"548 Stefan de Vrij Vrij\n",
"549 Walace Walace\n",
"550 Sebastian Walukiewicz Walukiewicz\n",
"551 Georginio Wijnaldum Wijnaldum\n",
"552 Harry Winks Winks\n",
"553 Przemysław Wiśniewski Wisniewski\n",
"554 Gerard Yepes Yepes\n",
"555 Mattia Zaccagni Zaccagni\n",
"556 Denis Zakaria Zakaria\n",
"557 Nicola Zalewski Zalewski\n",
"558 Andre-Frank Zambo Anguissa Anguissa\n",
"559 Luca Zanimacchia Zanimacchia\n",
"560 Nicolò Zaniolo Zaniolo\n",
"561 Alessandro Zanoli Zanoli\n",
"562 Alessandro Zanoli Zanoli\n",
"563 Mattia Zanotti Zanotti\n",
"564 Duván Zapata Zapata\n",
"565 Davide Zappacosta Zappacosta\n",
"566 Karim Zedadka Zedadka\n",
"567 Deyovaisio Zeefuik Zeefuik\n",
"568 Marvin Zeegelaar Zeegelaar\n",
"569 Alessio Zerbin Zerbin\n",
"570 Piotr Zieliński Zielinski\n",
"571 David Zima Zima\n",
"572 Joshua Zirkzee Zirkzee\n",
"573 Jeroen Zoet Zoet\n",
"574 Nadir Zortea Zortea\n",
"575 Nadir Zortea Zortea\n",
"576 Petar Zovko Zovko\n",
"577 Szymon Żurkowski Zurkowski\n",
"578 Szymon Żurkowski Zurkowski\n",
"579 Milan Đurić uric\n",
"580 Filip Đuričić uricic\n",
"581 Emil Audero Audero\n",
"582 Francesco Bardi Bardi\n",
"583 Marco Carnesecchi Carnesecchi\n",
"584 Michele Cerofolini Cerofolini\n",
"585 Andrea Consigli Consigli\n",
"586 Alessio Cragno Cragno\n",
"587 Michele Di Gregorio Gregorio\n",
"588 Bartłomiej Drągowski Dragowski\n",
"589 Wladimiro Falcone Falcone\n",
"590 Pierluigi Gollini Gollini\n",
"591 Pierluigi Gollini Gollini\n",
"592 Samir Handanović Handanovic\n",
"593 Mike Maignan Maignan\n",
"594 Federico Marchetti Marchetti\n",
"595 Luís Maximiano Maximiano\n",
"596 Alex Meret Meret\n",
"597 Vanja Milinković-Savić Milinkovic-Savic\n",
"598 Lorenzo Montipò Montipo\n",
"599 Juan Musso Musso\n",
"600 Guillermo Ochoa Ochoa\n",
"601 André Onana Onana\n",
"602 Rui Patrício Patricio\n",
"603 Gianluca Pegolo Pegolo\n",
"604 Simone Perilli Perilli\n",
"605 Mattia Perin Perin\n",
"606 Samuele Perisan Perisan\n",
"607 Ivan Provedel Provedel\n",
"608 Ionuț Radu Radu\n",
"609 Nicola Ravaglia Ravaglia\n",
"610 Luigi Sepe Sepe\n",
"611 Marco Silvestri Silvestri\n",
"612 Salvatore Sirigu Sirigu\n",
"613 Łukasz Skorupski Skorupski\n",
"614 Marco Sportiello Sportiello\n",
"615 Wojciech Szczęsny Szczesny\n",
"616 Ciprian Tătărușanu Tatarusanu\n",
"617 Pietro Terracciano Terracciano\n",
"618 Martin Turk Turk\n",
"619 Guglielmo Vicario Vicario\n",
"620 Jeroen Zoet Zoet\n",
"621 Petar Zovko Zovko\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": 7,
"id": "3e759b1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ostigard\n",
"Kim\n",
"Hojlund\n",
"Gytkjaer\n",
"Augusto\n",
"Maehle\n",
"Kjaer\n",
"Djuricic\n",
"Djuric\n",
"Cabral\n",
"Alvarez\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" FROM | \n",
" TO | \n",
" TEAM | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" stigard | \n",
" Ostigard | \n",
" Napoli | \n",
"
\n",
" \n",
" | 1 | \n",
" Min-jae | \n",
" Kim | \n",
" Napoli | \n",
"
\n",
" \n",
" | 2 | \n",
" Hjlund | \n",
" Hojlund | \n",
" Atalanta | \n",
"
\n",
" \n",
" | 3 | \n",
" Gytkjr | \n",
" Gytkjaer | \n",
" Monza | \n",
"
\n",
" \n",
" | 4 | \n",
" Carlos | \n",
" Augusto | \n",
" Monza | \n",
"
\n",
" \n",
" | 5 | \n",
" Mhle | \n",
" Maehle | \n",
" Atalanta | \n",
"
\n",
" \n",
" | 6 | \n",
" Kjr | \n",
" Kjaer | \n",
" Milan | \n",
"
\n",
" \n",
" | 7 | \n",
" uricic | \n",
" Djuricic | \n",
" Sampdoria | \n",
"
\n",
" \n",
" | 8 | \n",
" uric | \n",
" Djuric | \n",
" Hellas Verona | \n",
"
\n",
" \n",
" | 9 | \n",
" Arthur | \n",
" Cabral | \n",
" Fiorentina | \n",
"
\n",
" \n",
" | 10 | \n",
" Martinez | \n",
" Alvarez | \n",
" Sassuolo | \n",
"
\n",
" \n",
"
\n",
"
"
],
"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 Monza\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"
]
},
"execution_count": 7,
"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": 8,
"id": "f96eaaa1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2263921821.py:17: 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",
" fc_players['surname'][i] = spl[-1]\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2263921821.py:18: 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",
" fc_players['initial'][i] = ''\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2263921821.py:14: 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",
" fc_players['surname'][i] = spl[-2]\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2263921821.py:15: 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",
" fc_players['initial'][i] = spl[-1][0]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" r | \n",
" name | \n",
" team | \n",
" surname | \n",
" initial | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 572 | \n",
" P | \n",
" Meret | \n",
" Napoli | \n",
" Meret | \n",
" | \n",
"
\n",
" \n",
" | 1 | \n",
" 2814 | \n",
" P | \n",
" Provedel | \n",
" Lazio | \n",
" Provedel | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 4964 | \n",
" P | \n",
" Vicario | \n",
" Empoli | \n",
" Vicario | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" 453 | \n",
" P | \n",
" Szczesny | \n",
" Juventus | \n",
" Szczesny | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" 2134 | \n",
" P | \n",
" Falcone | \n",
" Lecce | \n",
" Falcone | \n",
" | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 538 | \n",
" 5512 | \n",
" A | \n",
" De Luca | \n",
" Sampdoria | \n",
" Luca | \n",
" | \n",
"
\n",
" \n",
" | 539 | \n",
" 5837 | \n",
" A | \n",
" Voelkerling Persson | \n",
" Lecce | \n",
" Persson | \n",
" | \n",
"
\n",
" \n",
" | 540 | \n",
" 6113 | \n",
" A | \n",
" Montevago | \n",
" Sampdoria | \n",
" Montevago | \n",
" | \n",
"
\n",
" \n",
" | 541 | \n",
" 6143 | \n",
" A | \n",
" Krollis | \n",
" Spezia | \n",
" Krollis | \n",
" | \n",
"
\n",
" \n",
" | 542 | \n",
" 6160 | \n",
" A | \n",
" Vivaldo | \n",
" Udinese | \n",
" Vivaldo | \n",
" | \n",
"
\n",
" \n",
"
\n",
"
543 rows × 6 columns
\n",
"
"
],
"text/plain": [
" id r name team surname initial\n",
"0 572 P Meret Napoli Meret \n",
"1 2814 P Provedel Lazio Provedel \n",
"2 4964 P Vicario Empoli Vicario \n",
"3 453 P Szczesny Juventus Szczesny \n",
"4 2134 P Falcone Lecce Falcone \n",
".. ... .. ... ... ... ...\n",
"538 5512 A De Luca Sampdoria Luca \n",
"539 5837 A Voelkerling Persson Lecce Persson \n",
"540 6113 A Montevago Sampdoria Montevago \n",
"541 6143 A Krollis Spezia Krollis \n",
"542 6160 A Vivaldo Udinese Vivaldo \n",
"\n",
"[543 rows x 6 columns]"
]
},
"execution_count": 8,
"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['surname'][i] = spl[-2]\n",
" fc_players['initial'][i] = spl[-1][0]\n",
" else:\n",
" fc_players['surname'][i] = spl[-1]\n",
" fc_players['initial'][i] = ''\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": 9,
"id": "9c50e4b5",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2200947104.py:4: 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",
" fc_players['fb_ID'][i] = -1\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2200947104.py:11: 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",
" fc_players['fb_ID'][i] = j\n"
]
}
],
"source": [
"fc_players['fb_ID'] = fc_players['id']\n",
"\n",
"for i in range(fc_players.shape[0]):\n",
" fc_players['fb_ID'][i] = -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['fb_ID'][i] = 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": 10,
"id": "18f6c5f2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mirante not found\n",
"Sarr M. not found\n",
"Lamanna not found\n",
"Ujkani not found\n",
"Berisha not found\n",
"Padelli not found\n",
"Cordaz not found\n",
"Pinsoglio not found\n",
"Fiorillo not found\n",
"Rossi F. not found\n",
"Ravaglia F. from previous team stats\n",
"Brancolini not found\n",
"Bleve not found\n",
"Berardi A. not found\n",
"Russo A. not found\n",
"Gemello not found\n",
"Boer not found\n",
"Adamonis not found\n",
"Marfella not found\n",
"Piana not found\n",
"Bagnolini not found\n",
"Svilar not found\n",
"Sorrentino A. not found\n",
"Ciezkowski not found\n",
"Saro not found\n",
"Vasquez D. not found\n",
"Bereszynski from previous team stats\n",
"Aiwu not found\n",
"Radu from previous team stats\n",
"Paletta not found\n",
"Fares not found\n",
"Romagna not found\n",
"Amey not found\n",
"Buta not found\n",
"Guessand A. not found\n",
"Guarino not found\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\362391242.py:10: 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",
" fc_players['fb_ID'][i] = j\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Machin not found\n",
"Akpa Akpro not found\n",
"Galdames not found\n",
"Darboe not found\n",
"Urbanski not found\n",
"Bertini not found\n",
"Trimboli not found\n",
"Samek not found\n",
"Degli Innocenti not found\n",
"Faticanti not found\n",
"Oddei not found\n",
"Kaio Jorge not found\n",
"Vivaldo not found\n"
]
}
],
"source": [
"exceptions = ['pellegrini', 'berardi', 'romagnoli'] # 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['fb_ID'][i] = 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": 11,
"id": "3b4a36af",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" r | \n",
" name | \n",
" team | \n",
" surname | \n",
" initial | \n",
" fb_ID | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 572 | \n",
" P | \n",
" Meret | \n",
" Napoli | \n",
" Meret | \n",
" | \n",
" 596 | \n",
"
\n",
" \n",
" | 1 | \n",
" 2814 | \n",
" P | \n",
" Provedel | \n",
" Lazio | \n",
" Provedel | \n",
" | \n",
" 607 | \n",
"
\n",
" \n",
" | 2 | \n",
" 4964 | \n",
" P | \n",
" Vicario | \n",
" Empoli | \n",
" Vicario | \n",
" | \n",
" 619 | \n",
"
\n",
" \n",
" | 3 | \n",
" 453 | \n",
" P | \n",
" Szczesny | \n",
" Juventus | \n",
" Szczesny | \n",
" | \n",
" 615 | \n",
"
\n",
" \n",
" | 4 | \n",
" 2134 | \n",
" P | \n",
" Falcone | \n",
" Lecce | \n",
" Falcone | \n",
" | \n",
" 589 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 538 | \n",
" 5512 | \n",
" A | \n",
" De Luca | \n",
" Sampdoria | \n",
" Luca | \n",
" | \n",
" 146 | \n",
"
\n",
" \n",
" | 539 | \n",
" 5837 | \n",
" A | \n",
" Voelkerling Persson | \n",
" Lecce | \n",
" Persson | \n",
" | \n",
" 543 | \n",
"
\n",
" \n",
" | 540 | \n",
" 6113 | \n",
" A | \n",
" Montevago | \n",
" Sampdoria | \n",
" Montevago | \n",
" | \n",
" 353 | \n",
"
\n",
" \n",
" | 541 | \n",
" 6143 | \n",
" A | \n",
" Krollis | \n",
" Spezia | \n",
" Krollis | \n",
" | \n",
" 278 | \n",
"
\n",
" \n",
" | 542 | \n",
" 6160 | \n",
" A | \n",
" Vivaldo | \n",
" Udinese | \n",
" Vivaldo | \n",
" | \n",
" -1 | \n",
"
\n",
" \n",
"
\n",
"
543 rows × 7 columns
\n",
"
"
],
"text/plain": [
" id r name team surname initial fb_ID\n",
"0 572 P Meret Napoli Meret 596\n",
"1 2814 P Provedel Lazio Provedel 607\n",
"2 4964 P Vicario Empoli Vicario 619\n",
"3 453 P Szczesny Juventus Szczesny 615\n",
"4 2134 P Falcone Lecce Falcone 589\n",
".. ... .. ... ... ... ... ...\n",
"538 5512 A De Luca Sampdoria Luca 146\n",
"539 5837 A Voelkerling Persson Lecce Persson 543\n",
"540 6113 A Montevago Sampdoria Montevago 353\n",
"541 6143 A Krollis Spezia Krollis 278\n",
"542 6160 A Vivaldo Udinese Vivaldo -1\n",
"\n",
"[543 rows x 7 columns]"
]
},
"execution_count": 11,
"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": 12,
"id": "1d73a312",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy] = 0\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\2261782218.py:9: 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",
" fc_players[columns_to_copy[j]][i] = outfield_players[columns_to_copy[j]][fc_players['fb_ID'][i]]\n"
]
}
],
"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",
" "
]
},
{
"cell_type": "code",
"execution_count": 13,
"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": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"keeper_players.columns[4:]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "eb9127a9",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:4: PerformanceWarning: DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`\n",
" fc_players[columns_to_copy[2:]] = 0 # add columns but do not override age and birth_year\n",
"C:\\Users\\nicol\\AppData\\Local\\Temp\\ipykernel_3044\\3664433845.py:11: 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",
" fc_players[columns_to_copy[j]][i] = keeper_players[columns_to_copy[j]][fc_players['fb_ID'][i] - delta_k]\n"
]
}
],
"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]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "da977789",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" r | \n",
" name | \n",
" team | \n",
" surname | \n",
" initial | \n",
" fb_ID | \n",
" age | \n",
" birth_year | \n",
" games | \n",
" ... | \n",
" gk_passes_length_avg | \n",
" gk_goal_kicks | \n",
" gk_pct_goal_kicks_launched | \n",
" gk_goal_kick_length_avg | \n",
" gk_crosses | \n",
" gk_crosses_stopped | \n",
" gk_crosses_stopped_pct | \n",
" gk_def_actions_outside_pen_area | \n",
" gk_def_actions_outside_pen_area_per90 | \n",
" gk_avg_distance_def_actions | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 572 | \n",
" P | \n",
" Meret | \n",
" Napoli | \n",
" Meret | \n",
" | \n",
" 596 | \n",
" 26-040 | \n",
" 1997 | \n",
" 0 | \n",
" ... | \n",
" 26.3 | \n",
" 189 | \n",
" 20.1 | \n",
" 26.9 | \n",
" 315 | \n",
" 10 | \n",
" 3.2 | \n",
" 35 | \n",
" 1.13 | \n",
" 17.1 | \n",
"
\n",
" \n",
" | 1 | \n",
" 2814 | \n",
" P | \n",
" Provedel | \n",
" Lazio | \n",
" Provedel | \n",
" | \n",
" 607 | \n",
" 29-045 | \n",
" 1994 | \n",
" 0 | \n",
" ... | \n",
" 33.3 | \n",
" 166 | \n",
" 36.1 | \n",
" 34.7 | \n",
" 422 | \n",
" 18 | \n",
" 4.3 | \n",
" 46 | \n",
" 1.44 | \n",
" 16.0 | \n",
"
\n",
" \n",
" | 2 | \n",
" 4964 | \n",
" P | \n",
" Vicario | \n",
" Empoli | \n",
" Vicario | \n",
" | \n",
" 619 | \n",
" 26-206 | \n",
" 1996 | \n",
" 0 | \n",
" ... | \n",
" 33.4 | \n",
" 142 | \n",
" 49.3 | \n",
" 42.6 | \n",
" 504 | \n",
" 28 | \n",
" 5.6 | \n",
" 15 | \n",
" 0.60 | \n",
" 10.7 | \n",
"
\n",
" \n",
" | 3 | \n",
" 453 | \n",
" P | \n",
" Szczesny | \n",
" Juventus | \n",
" Szczesny | \n",
" | \n",
" 615 | \n",
" 33-013 | \n",
" 1990 | \n",
" 0 | \n",
" ... | \n",
" 34.4 | \n",
" 119 | \n",
" 49.6 | \n",
" 41.4 | \n",
" 312 | \n",
" 9 | \n",
" 2.9 | \n",
" 19 | \n",
" 0.85 | \n",
" 15.1 | \n",
"
\n",
" \n",
" | 4 | \n",
" 2134 | \n",
" P | \n",
" Falcone | \n",
" Lecce | \n",
" Falcone | \n",
" | \n",
" 589 | \n",
" 28-019 | \n",
" 1995 | \n",
" 0 | \n",
" ... | \n",
" 41.8 | \n",
" 228 | \n",
" 77.6 | \n",
" 52.6 | \n",
" 452 | \n",
" 22 | \n",
" 4.9 | \n",
" 36 | \n",
" 1.13 | \n",
" 13.9 | \n",
"
\n",
" \n",
" | ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" | 538 | \n",
" 5512 | \n",
" A | \n",
" De Luca | \n",
" Sampdoria | \n",
" Luca | \n",
" | \n",
" 146 | \n",
" 24-288 | \n",
" 1998 | \n",
" 2 | \n",
" ... | \n",
" 0.0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0.00 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 539 | \n",
" 5837 | \n",
" A | \n",
" Voelkerling Persson | \n",
" Lecce | \n",
" Persson | \n",
" | \n",
" 543 | \n",
" 20-106 | \n",
" 2003 | \n",
" 7 | \n",
" ... | \n",
" 0.0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0.00 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 540 | \n",
" 6113 | \n",
" A | \n",
" Montevago | \n",
" Sampdoria | \n",
" Montevago | \n",
" | \n",
" 353 | \n",
" 20-044 | \n",
" 2003 | \n",
" 6 | \n",
" ... | \n",
" 0.0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0.00 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 541 | \n",
" 6143 | \n",
" A | \n",
" Krollis | \n",
" Spezia | \n",
" Krollis | \n",
" | \n",
" 278 | \n",
" 21-185 | \n",
" 2001 | \n",
" 2 | \n",
" ... | \n",
" 0.0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0.00 | \n",
" 0.0 | \n",
"
\n",
" \n",
" | 542 | \n",
" 6160 | \n",
" A | \n",
" Vivaldo | \n",
" Udinese | \n",
" Vivaldo | \n",
" | \n",
" -1 | \n",
" 0 | \n",
" 0 | \n",
" 0 | \n",
" ... | \n",
" 0.0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0 | \n",
" 0.0 | \n",
" 0 | \n",
" 0.00 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
543 rows × 158 columns
\n",
"
"
],
"text/plain": [
" id r name team surname initial fb_ID \\\n",
"0 572 P Meret Napoli Meret 596 \n",
"1 2814 P Provedel Lazio Provedel 607 \n",
"2 4964 P Vicario Empoli Vicario 619 \n",
"3 453 P Szczesny Juventus Szczesny 615 \n",
"4 2134 P Falcone Lecce Falcone 589 \n",
".. ... .. ... ... ... ... ... \n",
"538 5512 A De Luca Sampdoria Luca 146 \n",
"539 5837 A Voelkerling Persson Lecce Persson 543 \n",
"540 6113 A Montevago Sampdoria Montevago 353 \n",
"541 6143 A Krollis Spezia Krollis 278 \n",
"542 6160 A Vivaldo Udinese Vivaldo -1 \n",
"\n",
" age birth_year games ... gk_passes_length_avg gk_goal_kicks \\\n",
"0 26-040 1997 0 ... 26.3 189 \n",
"1 29-045 1994 0 ... 33.3 166 \n",
"2 26-206 1996 0 ... 33.4 142 \n",
"3 33-013 1990 0 ... 34.4 119 \n",
"4 28-019 1995 0 ... 41.8 228 \n",
".. ... ... ... ... ... ... \n",
"538 24-288 1998 2 ... 0.0 0 \n",
"539 20-106 2003 7 ... 0.0 0 \n",
"540 20-044 2003 6 ... 0.0 0 \n",
"541 21-185 2001 2 ... 0.0 0 \n",
"542 0 0 0 ... 0.0 0 \n",
"\n",
" gk_pct_goal_kicks_launched gk_goal_kick_length_avg gk_crosses \\\n",
"0 20.1 26.9 315 \n",
"1 36.1 34.7 422 \n",
"2 49.3 42.6 504 \n",
"3 49.6 41.4 312 \n",
"4 77.6 52.6 452 \n",
".. ... ... ... \n",
"538 0.0 0.0 0 \n",
"539 0.0 0.0 0 \n",
"540 0.0 0.0 0 \n",
"541 0.0 0.0 0 \n",
"542 0.0 0.0 0 \n",
"\n",
" gk_crosses_stopped gk_crosses_stopped_pct \\\n",
"0 10 3.2 \n",
"1 18 4.3 \n",
"2 28 5.6 \n",
"3 9 2.9 \n",
"4 22 4.9 \n",
".. ... ... \n",
"538 0 0.0 \n",
"539 0 0.0 \n",
"540 0 0.0 \n",
"541 0 0.0 \n",
"542 0 0.0 \n",
"\n",
" gk_def_actions_outside_pen_area gk_def_actions_outside_pen_area_per90 \\\n",
"0 35 1.13 \n",
"1 46 1.44 \n",
"2 15 0.60 \n",
"3 19 0.85 \n",
"4 36 1.13 \n",
".. ... ... \n",
"538 0 0.00 \n",
"539 0 0.00 \n",
"540 0 0.00 \n",
"541 0 0.00 \n",
"542 0 0.00 \n",
"\n",
" gk_avg_distance_def_actions \n",
"0 17.1 \n",
"1 16.0 \n",
"2 10.7 \n",
"3 15.1 \n",
"4 13.9 \n",
".. ... \n",
"538 0.0 \n",
"539 0.0 \n",
"540 0.0 \n",
"541 0.0 \n",
"542 0.0 \n",
"\n",
"[543 rows x 158 columns]"
]
},
"execution_count": 15,
"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": 16,
"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": 17,
"id": "61fac91a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"vote_avg 6.219162\n",
"vote_std 0.463073\n",
"dtype: float64\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" vote_avg | \n",
" vote_std | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 6.193548 | \n",
" 0.414990 | \n",
"
\n",
" \n",
" | 1 | \n",
" 6.296875 | \n",
" 0.430468 | \n",
"
\n",
" \n",
" | 2 | \n",
" 6.440000 | \n",
" 0.382623 | \n",
"
\n",
" \n",
" | 3 | \n",
" 6.108696 | \n",
" 0.328254 | \n",
"
\n",
" \n",
" | 4 | \n",
" 6.250000 | \n",
" 0.530330 | \n",
"
\n",
" \n",
" | 5 | \n",
" 6.265625 | \n",
" 0.414284 | \n",
"
\n",
" \n",
" | 6 | \n",
" 6.000000 | \n",
" 0.586302 | \n",
"
\n",
" \n",
" | 7 | \n",
" 6.142857 | \n",
" 0.349927 | \n",
"
\n",
" \n",
" | 8 | \n",
" 6.294118 | \n",
" 0.455645 | \n",
"
\n",
" \n",
" | 9 | \n",
" 6.031250 | \n",
" 0.431884 | \n",
"
\n",
" \n",
" | 10 | \n",
" 6.136364 | \n",
" 0.431220 | \n",
"
\n",
" \n",
" | 11 | \n",
" 6.218750 | \n",
" 0.352170 | \n",
"
\n",
" \n",
" | 12 | \n",
" 6.369565 | \n",
" 0.493818 | \n",
"
\n",
" \n",
" | 13 | \n",
" 6.322581 | \n",
" 0.516633 | \n",
"
\n",
" \n",
" | 14 | \n",
" 6.300000 | \n",
" 0.447214 | \n",
"
\n",
" \n",
" | 15 | \n",
" 6.258065 | \n",
" 0.472996 | \n",
"
\n",
" \n",
" | 16 | \n",
" 6.241935 | \n",
" 0.620496 | \n",
"
\n",
" \n",
" | 17 | \n",
" 6.050000 | \n",
" 0.537742 | \n",
"
\n",
" \n",
" | 18 | \n",
" 6.258621 | \n",
" 0.502077 | \n",
"
\n",
" \n",
" | 19 | \n",
" 6.000000 | \n",
" 0.451335 | \n",
"
\n",
" \n",
" | 20 | \n",
" 6.000000 | \n",
" 0.395285 | \n",
"
\n",
" \n",
" | 21 | \n",
" 6.090909 | \n",
" 0.467983 | \n",
"
\n",
" \n",
" | 22 | \n",
" 6.150000 | \n",
" 0.502494 | \n",
"
\n",
" \n",
" | 23 | \n",
" 6.450000 | \n",
" 0.522015 | \n",
"
\n",
" \n",
" | 24 | \n",
" 6.633333 | \n",
" 0.590668 | \n",
"
\n",
" \n",
" | 25 | \n",
" 6.214286 | \n",
" 0.364216 | \n",
"
\n",
" \n",
" | 26 | \n",
" 6.200000 | \n",
" 0.509902 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" vote_avg vote_std\n",
"0 6.193548 0.414990\n",
"1 6.296875 0.430468\n",
"2 6.440000 0.382623\n",
"3 6.108696 0.328254\n",
"4 6.250000 0.530330\n",
"5 6.265625 0.414284\n",
"6 6.000000 0.586302\n",
"7 6.142857 0.349927\n",
"8 6.294118 0.455645\n",
"9 6.031250 0.431884\n",
"10 6.136364 0.431220\n",
"11 6.218750 0.352170\n",
"12 6.369565 0.493818\n",
"13 6.322581 0.516633\n",
"14 6.300000 0.447214\n",
"15 6.258065 0.472996\n",
"16 6.241935 0.620496\n",
"17 6.050000 0.537742\n",
"18 6.258621 0.502077\n",
"19 6.000000 0.451335\n",
"20 6.000000 0.395285\n",
"21 6.090909 0.467983\n",
"22 6.150000 0.502494\n",
"23 6.450000 0.522015\n",
"24 6.633333 0.590668\n",
"25 6.214286 0.364216\n",
"26 6.200000 0.509902"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"min_votes = 6\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": null,
"id": "c9312080",
"metadata": {},
"outputs": [],
"source": [
"min_votes = 6\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": null,
"id": "b2570ce5",
"metadata": {},
"outputs": [],
"source": [
"fc_players = pd.concat([fc_players, perf_df], axis = 1)\n",
"\n",
"fc_players"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7620abe",
"metadata": {},
"outputs": [],
"source": [
"fc_players.columns[123]"
]
},
{
"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": null,
"id": "700b7a7d",
"metadata": {},
"outputs": [],
"source": [
"min_gk_games = 6\n",
"\n",
"fc_players_newgk = fc_players.copy()\n",
"\n",
"columns_to_avg = fc_players.columns[123:] # 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": null,
"id": "2d9eee99",
"metadata": {},
"outputs": [],
"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": null,
"id": "8336c025",
"metadata": {},
"outputs": [],
"source": [
"fc_players.to_excel('mid_outputs/players_stats.xlsx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3fc9b1b",
"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
}