{ "cells": [ { "cell_type": "markdown", "id": "d065632b", "metadata": {}, "source": [ "Scraping from http://fbref.com\n", "\n", "Data:\n", "- outfield players stats\n", "- goalkeepers stats\n", "- team stats (of and against)\n", "\n", "Original code by parth1902:\n", "https://github.com/parth1902/Scrape-FBref-data" ] }, { "cell_type": "code", "execution_count": 1, "id": "3b8d2e7f", "metadata": {}, "outputs": [], "source": [ "import requests\n", "from bs4 import BeautifulSoup\n", "import pandas as pd\n", "import numpy as np\n", "import re\n", "import sys, getopt\n", "import csv\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "ab920c85", "metadata": {}, "outputs": [], "source": [ "#standard(stats)\n", "stats = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"games\",\"games_starts\",\"minutes\",\"goals\",\"assists\",\"pens_made\",\"pens_att\",\"cards_yellow\",\"cards_red\",\"goals_per90\",\"assists_per90\",\"goals_assists_per90\",\"goals_pens_per90\",\"goals_assists_pens_per90\",\"xg\",\"npxg\",\"xa\",\"xg_per90\",\"xa_per90\",\"xg_xa_per90\",\"npxg_per90\",\"npxg_xa_per90\"]\n", "stats3 = [\"players_used\",\"possession\",\"games\",\"games_starts\",\"minutes\",\"goals\",\"assists\",\"pens_made\",\"pens_att\",\"cards_yellow\",\"cards_red\",\"goals_per90\",\"assists_per90\",\"goals_assists_per90\",\"goals_pens_per90\",\"goals_assists_pens_per90\",\"xg\",\"npxg\",\"xa\",\"xg_per90\",\"xa_per90\",\"xg_xa_per90\",\"npxg_per90\",\"npxg_xa_per90\"] \n", "#goalkeeping(keepers)\n", "keepers = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"gk_games\",\"gk_games_starts\",\"gk_minutes\",\"gk_goals_against\",\"gk_goals_against_per90\",\"gk_shots_on_target_against\",\"gk_saves\",\"gk_save_pct\",\"gk_wins\",\"gk_ties\",\"gk_losses\",\"gk_clean_sheets\",\"gk_clean_sheets_pct\",\"gk_pens_att\",\"gk_pens_allowed\",\"gk_pens_saved\",\"gk_pens_missed\"]\n", "keepers3 = [\"players_used\",\"gk_games\",\"gk_games_starts\",\"gk_minutes\",\"gk_goals_against\",\"gk_goals_against_per90\",\"gk_shots_on_target_against\",\"gk_saves\",\"gk_save_pct\",\"gk_wins\",\"gk_ties\",\"gk_losses\",\"gk_clean_sheets\",\"gk_clean_sheets_pct\",\"gk_pens_att\",\"gk_pens_allowed\",\"gk_pens_saved\",\"gk_pens_missed\"]\n", "#advance goalkeeping(keepersadv)\n", "keepersadv = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"gk_goals_against\",\"gk_pens_allowed\",\"gk_free_kick_goals_against\",\"gk_corner_kick_goals_against\",\"gk_own_goals_against\",\"gk_psxg\",\"gk_psnpxg_per_shot_on_target_against\",\"gk_psxg_net\",\"gk_psxg_net_per90\",\"gk_passes_completed_launched\",\"gk_passes_launched\",\"gk_passes_pct_launched\",\"gk_passes\",\"gk_passes_throws\",\"gk_pct_passes_launched\",\"gk_passes_length_avg\",\"gk_goal_kicks\",\"gk_pct_goal_kicks_launched\",\"gk_goal_kick_length_avg\",\"gk_crosses\",\"gk_crosses_stopped\",\"gk_crosses_stopped_pct\",\"gk_def_actions_outside_pen_area\",\"gk_def_actions_outside_pen_area_per90\",\"gk_avg_distance_def_actions\"]\n", "keepersadv2 = [\"minutes_90s\",\"gk_goals_against\",\"gk_pens_allowed\",\"gk_free_kick_goals_against\",\"gk_corner_kick_goals_against\",\"gk_own_goals_against\",\"gk_psxg\",\"gk_psnpxg_per_shot_on_target_against\",\"gk_psxg_net\",\"gk_psxg_net_per90\",\"gk_passes_completed_launched\",\"gk_passes_launched\",\"gk_passes_pct_launched\",\"gk_passes\",\"gk_passes_throws\",\"gk_pct_passes_launched\",\"gk_passes_length_avg\",\"gk_goal_kicks\",\"gk_pct_goal_kicks_launched\",\"gk_goal_kick_length_avg\",\"gk_crosses\",\"gk_crosses_stopped\",\"gk_crosses_stopped_pct\",\"gk_def_actions_outside_pen_area\",\"gk_def_actions_outside_pen_area_per90\",\"gk_avg_distance_def_actions\"]\n", "#shooting(shooting)\n", "shooting = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"goals\",\"pens_made\",\"pens_att\",\"shots_total\",\"shots_on_target\",\"shots_free_kicks\",\"shots_on_target_pct\",\"shots_total_per90\",\"shots_on_target_per90\",\"goals_per_shot\",\"goals_per_shot_on_target\",\"xg\",\"npxg\",\"npxg_per_shot\",\"xg_net\",\"npxg_net\"]\n", "shooting2 = [\"minutes_90s\",\"goals\",\"pens_made\",\"pens_att\",\"shots_total\",\"shots_on_target\",\"shots_free_kicks\",\"shots_on_target_pct\",\"shots_total_per90\",\"shots_on_target_per90\",\"goals_per_shot\",\"goals_per_shot_on_target\",\"xg\",\"npxg\",\"npxg_per_shot\",\"xg_net\",\"npxg_net\"]\n", "shooting3 = [\"goals\",\"pens_made\",\"pens_att\",\"shots_total\",\"shots_on_target\",\"shots_free_kicks\",\"shots_on_target_pct\",\"shots_total_per90\",\"shots_on_target_per90\",\"goals_per_shot\",\"goals_per_shot_on_target\",\"xg\",\"npxg\",\"npxg_per_shot\",\"xg_net\",\"npxg_net\"]\n", "#passing(passing)\n", "passing = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"passes_completed\",\"passes\",\"passes_pct\",\"passes_total_distance\",\"passes_progressive_distance\",\"passes_completed_short\",\"passes_short\",\"passes_pct_short\",\"passes_completed_medium\",\"passes_medium\",\"passes_pct_medium\",\"passes_completed_long\",\"passes_long\",\"passes_pct_long\",\"assists\",\"xa\",\"xa_net\",\"assisted_shots\",\"passes_into_final_third\",\"passes_into_penalty_area\",\"crosses_into_penalty_area\",\"progressive_passes\"]\n", "passing2 = [\"passes_completed\",\"passes\",\"passes_pct\",\"passes_total_distance\",\"passes_progressive_distance\",\"passes_completed_short\",\"passes_short\",\"passes_pct_short\",\"passes_completed_medium\",\"passes_medium\",\"passes_pct_medium\",\"passes_completed_long\",\"passes_long\",\"passes_pct_long\",\"assists\",\"xa\",\"xa_net\",\"assisted_shots\",\"passes_into_final_third\",\"passes_into_penalty_area\",\"crosses_into_penalty_area\",\"progressive_passes\"]\n", "#passtypes(passing_types)\n", "passing_types = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"passes\",\"passes_live\",\"passes_dead\",\"passes_free_kicks\",\"through_balls\",\"passes_pressure\",\"passes_switches\",\"crosses\",\"corner_kicks\",\"corner_kicks_in\",\"corner_kicks_out\",\"corner_kicks_straight\",\"passes_ground\",\"passes_low\",\"passes_high\",\"passes_left_foot\",\"passes_right_foot\",\"passes_head\",\"throw_ins\",\"passes_other_body\",\"passes_completed\",\"passes_offsides\",\"passes_oob\",\"passes_intercepted\",\"passes_blocked\"]\n", "passing_types2 = [\"passes\",\"passes_live\",\"passes_dead\",\"passes_free_kicks\",\"through_balls\",\"passes_pressure\",\"passes_switches\",\"crosses\",\"corner_kicks\",\"corner_kicks_in\",\"corner_kicks_out\",\"corner_kicks_straight\",\"passes_ground\",\"passes_low\",\"passes_high\",\"passes_left_foot\",\"passes_right_foot\",\"passes_head\",\"throw_ins\",\"passes_other_body\",\"passes_completed\",\"passes_offsides\",\"passes_oob\",\"passes_intercepted\",\"passes_blocked\"]\n", "#goal and shot creation(gca)\n", "gca = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"sca\",\"sca_per90\",\"sca_passes_live\",\"sca_passes_dead\",\"sca_dribbles\",\"sca_shots\",\"sca_fouled\",\"gca\",\"gca_per90\",\"gca_passes_live\",\"gca_passes_dead\",\"gca_dribbles\",\"gca_shots\",\"gca_fouled\",\"gca_defense\"]\n", "gca2 = [\"sca\",\"sca_per90\",\"sca_passes_live\",\"sca_passes_dead\",\"sca_dribbles\",\"sca_shots\",\"sca_fouled\",\"gca\",\"gca_per90\",\"gca_passes_live\",\"gca_passes_dead\",\"gca_dribbles\",\"gca_shots\",\"gca_fouled\",\"gca_defense\"]\n", "#defensive actions(defense)\n", "defense = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"tackles\",\"tackles_won\",\"tackles_def_3rd\",\"tackles_mid_3rd\",\"tackles_att_3rd\",\"dribble_tackles\",\"dribbles_vs\",\"dribble_tackles_pct\",\"dribbled_past\",\"pressures\",\"pressure_regains\",\"pressure_regain_pct\",\"pressures_def_3rd\",\"pressures_mid_3rd\",\"pressures_att_3rd\",\"blocks\",\"blocked_shots\",\"blocked_shots_saves\",\"blocked_passes\",\"interceptions\",\"clearances\",\"errors\"]\n", "defense2 = [\"tackles\",\"tackles_won\",\"tackles_def_3rd\",\"tackles_mid_3rd\",\"tackles_att_3rd\",\"dribble_tackles\",\"dribbles_vs\",\"dribble_tackles_pct\",\"dribbled_past\",\"pressures\",\"pressure_regains\",\"pressure_regain_pct\",\"pressures_def_3rd\",\"pressures_mid_3rd\",\"pressures_att_3rd\",\"blocks\",\"blocked_shots\",\"blocked_shots_saves\",\"blocked_passes\",\"interceptions\",\"clearances\",\"errors\"]\n", "#possession(possession)\n", "possession = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"touches\",\"touches_def_pen_area\",\"touches_def_3rd\",\"touches_mid_3rd\",\"touches_att_3rd\",\"touches_att_pen_area\",\"touches_live_ball\",\"dribbles_completed\",\"dribbles\",\"dribbles_completed_pct\",\"players_dribbled_past\",\"nutmegs\",\"carries\",\"carry_distance\",\"carry_progressive_distance\",\"progressive_carries\",\"carries_into_final_third\",\"carries_into_penalty_area\",\"pass_targets\",\"passes_received\",\"passes_received_pct\",\"miscontrols\",\"dispossessed\"]\n", "possession2 = [\"touches\",\"touches_def_pen_area\",\"touches_def_3rd\",\"touches_mid_3rd\",\"touches_att_3rd\",\"touches_att_pen_area\",\"touches_live_ball\",\"dribbles_completed\",\"dribbles\",\"dribbles_completed_pct\",\"players_dribbled_past\",\"nutmegs\",\"carries\",\"carry_distance\",\"carry_progressive_distance\",\"progressive_carries\",\"carries_into_final_third\",\"carries_into_penalty_area\",\"pass_targets\",\"passes_received\",\"passes_received_pct\",\"miscontrols\",\"dispossessed\"]\n", "#playingtime(playingtime)\n", "playingtime = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"games\",\"minutes\",\"minutes_per_game\",\"minutes_pct\",\"games_starts\",\"minutes_per_start\",\"games_subs\",\"minutes_per_sub\",\"unused_subs\",\"points_per_match\",\"on_goals_for\",\"on_goals_against\",\"plus_minus\",\"plus_minus_per90\",\"plus_minus_wowy\",\"on_xg_for\",\"on_xg_against\",\"xg_plus_minus\",\"xg_plus_minus_per90\",\"xg_plus_minus_wowy\"]\n", "playingtime2 = [\"games\",\"minutes\",\"minutes_per_game\",\"minutes_pct\",\"games_starts\",\"minutes_per_start\",\"games_subs\",\"minutes_per_sub\",\"unused_subs\",\"points_per_match\",\"on_goals_for\",\"on_goals_against\",\"plus_minus\",\"plus_minus_per90\",\"plus_minus_wowy\",\"on_xg_for\",\"on_xg_against\",\"xg_plus_minus\",\"xg_plus_minus_per90\",\"xg_plus_minus_wowy\"]\n", "#miscallaneous(misc)\n", "misc = [\"player\",\"nationality\",\"position\",\"team\",\"age\",\"birth_year\",\"minutes_90s\",\"cards_yellow\",\"cards_red\",\"cards_yellow_red\",\"fouls\",\"fouled\",\"offsides\",\"crosses\",\"interceptions\",\"tackles_won\",\"pens_won\",\"pens_conceded\",\"own_goals\",\"ball_recoveries\",\"aerials_won\",\"aerials_lost\",\"aerials_won_pct\"]\n", "misc2 = [\"cards_yellow\",\"cards_red\",\"cards_yellow_red\",\"fouls\",\"fouled\",\"offsides\",\"crosses\",\"interceptions\",\"tackles_won\",\"pens_won\",\"pens_conceded\",\"own_goals\",\"ball_recoveries\",\"aerials_won\",\"aerials_lost\",\"aerials_won_pct\"]\n", "\n", "def get_tables(url,text):\n", " headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}\n", "\n", " res = requests.get(url, headers = headers)\n", " ## The next two lines get around the issue with comments breaking the parsing.\n", " comm = re.compile(\"\")\n", " soup = BeautifulSoup(comm.sub(\"\",res.text),'lxml')\n", " all_tables = soup.findAll(\"tbody\")\n", " \n", " team_table = all_tables[0]\n", " team_vs_table = all_tables[1]\n", " player_table = all_tables[2]\n", " if text == 'for':\n", " return player_table, team_table\n", " if text == 'vs':\n", " return player_table, team_vs_table\n", "\n", "def get_frame(features, player_table):\n", " pre_df_player = dict()\n", " features_wanted_player = features\n", " rows_player = player_table.find_all('tr')\n", " for row in rows_player:\n", " if(row.find('th',{\"scope\":\"row\"}) != None):\n", " \n", " for f in features_wanted_player:\n", " cell = row.find(\"td\",{\"data-stat\": f})\n", " if(cell == None):\n", " continue\n", " a = cell.text.strip().encode()\n", " text=a.decode(\"utf-8\")\n", " if(text == ''):\n", " text = '0'\n", " if((f!='player')&(f!='nationality')&(f!='position')&(f!='squad')&(f!='age')&(f!='birth_year')&(f!='team')):\n", " text = float(text.replace(',','')) \n", " if f in pre_df_player:\n", " pre_df_player[f].append(text)\n", " else:\n", " pre_df_player[f] = [text]\n", " df_player = pd.DataFrame.from_dict(pre_df_player)\n", " return df_player\n", "\n", "def get_frame_team(features, team_table):\n", " pre_df_squad = dict()\n", " #Note: features does not contain squad name, it requires special treatment\n", " features_wanted_squad = features\n", " rows_squad = team_table.find_all('tr')\n", " for row in rows_squad:\n", " if(row.find('th',{\"scope\":\"row\"}) != None):\n", " name = row.find('th',{\"data-stat\":\"team\"}).text.strip().encode().decode(\"utf-8\")\n", " if 'team' in pre_df_squad:\n", " pre_df_squad['team'].append(name)\n", " else:\n", " pre_df_squad['team'] = [name]\n", " for f in features_wanted_squad:\n", " cell = row.find(\"td\",{\"data-stat\": f})\n", " if(cell == None):\n", " continue\n", " a = cell.text.strip().encode()\n", " text=a.decode(\"utf-8\")\n", " if(text == ''):\n", " text = '0'\n", " if((f!='player')&(f!='nationality')&(f!='position')&(f!='squad')&(f!='age')&(f!='birth_year')&(f!='team')):\n", " text = float(text.replace(',',''))\n", " if f in pre_df_squad:\n", " pre_df_squad[f].append(text)\n", " else:\n", " pre_df_squad[f] = [text]\n", " df_squad = pd.DataFrame.from_dict(pre_df_squad)\n", " return df_squad\n", "\n", "def get_frame_team_2(features, team_table):\n", " pre_df_squad = dict()\n", " #Note: features does not contain squad name, it requires special treatment\n", " features_wanted_squad = features\n", " rows_squad = team_table.find_all('tr')\n", " for row in rows_squad:\n", " if(row.find('th',{\"scope\":\"row\"}) != None):\n", " name = row.find('th',{\"data-stat\":\"squad\"}).text.strip().encode().decode(\"utf-8\")\n", " if 'squad' in pre_df_squad:\n", " pre_df_squad['squad'].append(name)\n", " else:\n", " pre_df_squad['squad'] = [name]\n", " for f in features_wanted_squad:\n", " cell = row.find(\"td\",{\"data-stat\": f})\n", " a = cell.text.strip().encode()\n", " text=a.decode(\"utf-8\")\n", " if(text == ''):\n", " text = '0'\n", " if((f!='player')&(f!='nationality')&(f!='position')&(f!='squad')&(f!='age')&(f!='birth_year')&(f!='team')):\n", " text = float(text.replace(',',''))\n", " print(f)\n", " if f in pre_df_squad:\n", " pre_df_squad[f].append(text)\n", " else:\n", " pre_df_squad[f] = [text]\n", " df_squad = pd.DataFrame.from_dict(pre_df_squad)\n", " return df_squad\n", "\n", "def frame_for_category(category,top,end,features):\n", " url = (top + category + end)\n", " player_table, team_table = get_tables(url,'for')\n", " df_player = get_frame(features, player_table)\n", " return df_player\n", "\n", "def frame_for_category_team(category,top,end,features,text):\n", " url = (top + category + end)\n", " player_table, team_table = get_tables(url,text)\n", " df_team = get_frame_team(features, team_table)\n", " return df_team\n", "\n", "\n", "\n", "\n", "#Function to get the player data for outfield player, includes all categories - standard stats, shooting\n", "#passing, passing types, goal and shot creation, defensive actions, possession, and miscallaneous\n", "def get_outfield_data(top, end):\n", " df1 = frame_for_category('stats',top,end,stats)\n", " df2 = frame_for_category('shooting',top,end,shooting2)\n", " df3 = frame_for_category('passing',top,end,passing2)\n", " df4 = frame_for_category('passing_types',top,end,passing_types2)\n", " df5 = frame_for_category('gca',top,end,gca2)\n", " df6 = frame_for_category('defense',top,end,defense2)\n", " df7 = frame_for_category('possession',top,end,possession2)\n", " df8 = frame_for_category('misc',top,end,misc2)\n", " df = pd.concat([df1, df2, df3, df4, df5, df6, df7, df8], axis=1)\n", " df = df.loc[:,~df.columns.duplicated()]\n", " return df\n", "\n", "\n", "#Function to get keeping and advance goalkeeping data\n", "def get_keeper_data(top,end):\n", " df1 = frame_for_category('keepers',top,end,keepers)\n", " df2 = frame_for_category('keepersadv',top,end,keepersadv2)\n", " df = pd.concat([df1, df2], axis=1)\n", " df = df.loc[:,~df.columns.duplicated()]\n", " return df\n", "\n", "\n", "\n", "#Function to get team-wise data accross all categories as mentioned above\n", "def get_team_data(top,end,text):\n", " df1 = frame_for_category_team('stats',top,end,stats3,text)\n", " df2 = frame_for_category_team('keepers',top,end,keepers3,text)\n", " df3 = frame_for_category_team('keepersadv',top,end,keepersadv2,text)\n", " df4 = frame_for_category_team('shooting',top,end,shooting3,text)\n", " df5 = frame_for_category_team('passing',top,end,passing2,text)\n", " df6 = frame_for_category_team('passing_types',top,end,passing_types2,text)\n", " df7 = frame_for_category_team('gca',top,end,gca2,text)\n", " df8 = frame_for_category_team('defense',top,end,defense2,text)\n", " df9 = frame_for_category_team('possession',top,end,possession2,text)\n", " df10 = frame_for_category_team('misc',top,end,misc2,text)\n", " df = pd.concat([df1, df2, df3, df4, df5, df6, df7, df8, df9, df10], axis=1)\n", " df = df.loc[:,~df.columns.duplicated()]\n", " return df" ] }, { "cell_type": "code", "execution_count": 3, "id": "9141a9ec", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playernationalitypositionteamagebirth_yeargamesgames_startsminutesgoals...foulsfouledoffsidespens_wonpens_concededown_goalsball_recoveriesaerials_wonaerials_lostaerials_won_pct
0Francesco Acerbiit ITADFInter35-22319881.01.090.00.0...2.01.00.00.00.00.04.03.00.0100.0
1Michel Aebischerch SUIMFBologna26-25819974.04.0347.00.0...7.05.00.00.00.00.023.02.03.040.0
2Luis Albertoes ESPMFLazio30-35819924.04.0360.02.0...3.05.00.00.00.00.024.02.04.033.3
3Pontus Almqvistse SWEFWLecce24-07319994.04.0347.01.0...3.08.01.01.00.00.015.00.03.00.0
4Lorenzo Amatucciit ITAMFFiorentina19-22820041.00.016.00.0...1.00.00.00.00.00.01.00.01.00.0
..................................................................
424Joshua Zirkzeenl NEDFWBologna22-12220014.04.0356.01.0...3.01.01.00.00.00.011.09.02.081.8
425Zitoao ANGFWCagliari21-19620024.03.0297.01.0...3.08.05.00.00.00.06.01.05.016.7
426Nadir Zorteait ITADFAtalanta24-09419993.00.096.01.0...3.00.00.00.00.00.04.00.01.00.0
427Milan Đurićba BIHFW,MFHellas Verona33-12219904.01.0152.00.0...7.01.02.00.00.00.04.021.014.060.0
428Mateusz Łęgowskipl POLMFSalernitana20-23520034.02.0161.00.0...3.03.00.00.00.00.014.04.05.044.4
\n", "

429 rows × 115 columns

\n", "
" ], "text/plain": [ " player nationality position team age birth_year \\\n", "0 Francesco Acerbi it ITA DF Inter 35-223 1988 \n", "1 Michel Aebischer ch SUI MF Bologna 26-258 1997 \n", "2 Luis Alberto es ESP MF Lazio 30-358 1992 \n", "3 Pontus Almqvist se SWE FW Lecce 24-073 1999 \n", "4 Lorenzo Amatucci it ITA MF Fiorentina 19-228 2004 \n", ".. ... ... ... ... ... ... \n", "424 Joshua Zirkzee nl NED FW Bologna 22-122 2001 \n", "425 Zito ao ANG FW Cagliari 21-196 2002 \n", "426 Nadir Zortea it ITA DF Atalanta 24-094 1999 \n", "427 Milan Đurić ba BIH FW,MF Hellas Verona 33-122 1990 \n", "428 Mateusz Łęgowski pl POL MF Salernitana 20-235 2003 \n", "\n", " games games_starts minutes goals ... fouls fouled offsides \\\n", "0 1.0 1.0 90.0 0.0 ... 2.0 1.0 0.0 \n", "1 4.0 4.0 347.0 0.0 ... 7.0 5.0 0.0 \n", "2 4.0 4.0 360.0 2.0 ... 3.0 5.0 0.0 \n", "3 4.0 4.0 347.0 1.0 ... 3.0 8.0 1.0 \n", "4 1.0 0.0 16.0 0.0 ... 1.0 0.0 0.0 \n", ".. ... ... ... ... ... ... ... ... \n", "424 4.0 4.0 356.0 1.0 ... 3.0 1.0 1.0 \n", "425 4.0 3.0 297.0 1.0 ... 3.0 8.0 5.0 \n", "426 3.0 0.0 96.0 1.0 ... 3.0 0.0 0.0 \n", "427 4.0 1.0 152.0 0.0 ... 7.0 1.0 2.0 \n", "428 4.0 2.0 161.0 0.0 ... 3.0 3.0 0.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 4.0 3.0 \n", "1 0.0 0.0 0.0 23.0 2.0 \n", "2 0.0 0.0 0.0 24.0 2.0 \n", "3 1.0 0.0 0.0 15.0 0.0 \n", "4 0.0 0.0 0.0 1.0 0.0 \n", ".. ... ... ... ... ... \n", "424 0.0 0.0 0.0 11.0 9.0 \n", "425 0.0 0.0 0.0 6.0 1.0 \n", "426 0.0 0.0 0.0 4.0 0.0 \n", "427 0.0 0.0 0.0 4.0 21.0 \n", "428 0.0 0.0 0.0 14.0 4.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 0.0 100.0 \n", "1 3.0 40.0 \n", "2 4.0 33.3 \n", "3 3.0 0.0 \n", "4 1.0 0.0 \n", ".. ... ... \n", "424 2.0 81.8 \n", "425 5.0 16.7 \n", "426 1.0 0.0 \n", "427 14.0 60.0 \n", "428 5.0 44.4 \n", "\n", "[429 rows x 115 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_outfield = get_outfield_data('https://fbref.com/en/comps/11/','/Serie-A-Stats')\n", "\n", "df_outfield.to_csv('fbref_data/outfield_players.csv', index=False)\n", "\n", "df_outfield" ] }, { "cell_type": "code", "execution_count": 4, "id": "9a30e27c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
playernationalitypositionteamagebirth_yeargk_gamesgk_games_startsgk_minutesgk_goals_against...gk_passes_length_avggk_goal_kicksgk_pct_goal_kicks_launchedgk_goal_kick_length_avggk_crossesgk_crosses_stoppedgk_crosses_stopped_pctgk_def_actions_outside_pen_areagk_def_actions_outside_pen_area_per90gk_avg_distance_def_actions
0Etrit Berishaal ALBGKEmpoli34-19519892.02.0180.09.0...27.59.022.227.023.01.04.32.01.0015.7
1Elia Caprileit ITAGKEmpoli22-02720011.01.090.01.0...42.64.050.050.310.02.020.02.02.0012.4
2Marco Carnesecchiit ITAGKAtalanta23-08220001.01.090.03.0...36.86.083.369.213.01.07.70.00.0014.5
3Michele Cerofoliniit ITAGKFrosinone24-26019991.01.090.01.0...38.35.060.045.818.00.00.00.00.000.0
4Oliver Christensendk DENGKFiorentina24-18319992.02.0180.06.0...33.28.062.549.415.00.00.03.01.5022.0
5Andrea Consigliit ITAGKSassuolo36-23719873.03.0270.05.0...37.134.026.528.146.02.04.33.01.0014.5
6Alessio Cragnoit ITAGKSassuolo29-08519941.01.090.04.0...37.19.033.334.69.00.00.07.07.0028.9
7Michele Di Gregorioit ITAGKMonza26-05619973.03.0270.05.0...28.722.040.940.345.02.04.42.00.6711.7
8Wladimiro Falconeit ITAGKLecce28-16219954.04.0360.04.0...31.042.052.438.754.02.03.72.00.5010.3
9Mike Maignanfr FRAGKMilan28-08019954.04.0360.07.0...29.223.060.947.052.012.023.13.00.759.8
10Josep Martinezes ESPGKGenoa25-11719984.04.0360.07.0...39.722.095.562.575.08.010.72.00.509.3
11Alex Meretit ITAGKNapoli26-18319974.04.0360.05.0...24.711.00.020.427.01.03.77.01.7518.2
12Vanja Milinković-Savićrs SRBGKTorino26-21319974.04.0360.04.0...38.136.075.061.333.03.09.15.01.2515.8
13Lorenzo Montipòit ITAGKHellas Verona27-21319964.04.0360.04.0...42.935.088.662.754.01.01.98.02.0019.4
14Juan Mussoar ARGGKAtalanta29-13819943.03.0270.02.0...29.318.055.646.128.02.07.18.02.6722.0
15Guillermo Ochoamx MEXGKSalernitana38-07019854.04.0360.08.0...35.935.054.343.663.04.06.31.00.257.8
16Rui Patríciopt PORGKRoma35-21819884.04.0360.06.0...29.317.011.822.134.02.05.92.00.5012.2
17Mattia Perinit ITAGKJuventus30-31519922.02.0180.01.0...29.111.09.118.926.02.07.72.01.0015.0
18Samuele Perisanit ITAGKEmpoli26-03119971.01.090.02.0...26.312.016.729.618.00.00.01.01.0021.0
19Ivan Provedelit ITAGKLazio29-18819944.04.0360.07.0...26.415.020.027.948.02.04.26.01.5015.7
20Boris Radunovićrs SRBGKCagliari27-11819964.04.0360.04.0...37.840.065.050.062.04.06.53.00.7512.5
21Marco Silvestriit ITAGKUdinese32-20319914.04.0360.04.0...29.732.031.335.449.00.00.03.00.7514.0
22Łukasz Skorupskipl POLGKBologna32-13919914.04.0360.04.0...32.122.031.834.257.02.03.52.00.5011.5
23Yann Sommerch SUIGKInter34-27819884.04.0360.01.0...30.829.020.728.341.02.04.90.00.006.5
24Alessandro Sorrentinoit ITAGKMonza21-17120021.01.090.01.0...21.02.00.023.08.01.012.50.00.009.0
25Wojciech Szczęsnypl POLGKJuventus33-15619902.02.0180.01.0...33.16.066.752.033.01.03.00.00.009.6
26Pietro Terraccianoit ITAGKFiorentina33-19719902.02.0180.03.0...33.19.011.125.016.01.06.31.00.5013.7
27Stefano Turatiit ITAGKFrosinone22-01620013.03.0270.05.0...26.013.053.841.733.02.06.13.01.0016.3
\n", "

28 rows × 47 columns

\n", "
" ], "text/plain": [ " player nationality position team age \\\n", "0 Etrit Berisha al ALB GK Empoli 34-195 \n", "1 Elia Caprile it ITA GK Empoli 22-027 \n", "2 Marco Carnesecchi it ITA GK Atalanta 23-082 \n", "3 Michele Cerofolini it ITA GK Frosinone 24-260 \n", "4 Oliver Christensen dk DEN GK Fiorentina 24-183 \n", "5 Andrea Consigli it ITA GK Sassuolo 36-237 \n", "6 Alessio Cragno it ITA GK Sassuolo 29-085 \n", "7 Michele Di Gregorio it ITA GK Monza 26-056 \n", "8 Wladimiro Falcone it ITA GK Lecce 28-162 \n", "9 Mike Maignan fr FRA GK Milan 28-080 \n", "10 Josep Martinez es ESP GK Genoa 25-117 \n", "11 Alex Meret it ITA GK Napoli 26-183 \n", "12 Vanja Milinković-Savić rs SRB GK Torino 26-213 \n", "13 Lorenzo Montipò it ITA GK Hellas Verona 27-213 \n", "14 Juan Musso ar ARG GK Atalanta 29-138 \n", "15 Guillermo Ochoa mx MEX GK Salernitana 38-070 \n", "16 Rui Patrício pt POR GK Roma 35-218 \n", "17 Mattia Perin it ITA GK Juventus 30-315 \n", "18 Samuele Perisan it ITA GK Empoli 26-031 \n", "19 Ivan Provedel it ITA GK Lazio 29-188 \n", "20 Boris Radunović rs SRB GK Cagliari 27-118 \n", "21 Marco Silvestri it ITA GK Udinese 32-203 \n", "22 Łukasz Skorupski pl POL GK Bologna 32-139 \n", "23 Yann Sommer ch SUI GK Inter 34-278 \n", "24 Alessandro Sorrentino it ITA GK Monza 21-171 \n", "25 Wojciech Szczęsny pl POL GK Juventus 33-156 \n", "26 Pietro Terracciano it ITA GK Fiorentina 33-197 \n", "27 Stefano Turati it ITA GK Frosinone 22-016 \n", "\n", " birth_year gk_games gk_games_starts gk_minutes gk_goals_against ... \\\n", "0 1989 2.0 2.0 180.0 9.0 ... \n", "1 2001 1.0 1.0 90.0 1.0 ... \n", "2 2000 1.0 1.0 90.0 3.0 ... \n", "3 1999 1.0 1.0 90.0 1.0 ... \n", "4 1999 2.0 2.0 180.0 6.0 ... \n", "5 1987 3.0 3.0 270.0 5.0 ... \n", "6 1994 1.0 1.0 90.0 4.0 ... \n", "7 1997 3.0 3.0 270.0 5.0 ... \n", "8 1995 4.0 4.0 360.0 4.0 ... \n", "9 1995 4.0 4.0 360.0 7.0 ... \n", "10 1998 4.0 4.0 360.0 7.0 ... \n", "11 1997 4.0 4.0 360.0 5.0 ... \n", "12 1997 4.0 4.0 360.0 4.0 ... \n", "13 1996 4.0 4.0 360.0 4.0 ... \n", "14 1994 3.0 3.0 270.0 2.0 ... \n", "15 1985 4.0 4.0 360.0 8.0 ... \n", "16 1988 4.0 4.0 360.0 6.0 ... \n", "17 1992 2.0 2.0 180.0 1.0 ... \n", "18 1997 1.0 1.0 90.0 2.0 ... \n", "19 1994 4.0 4.0 360.0 7.0 ... \n", "20 1996 4.0 4.0 360.0 4.0 ... \n", "21 1991 4.0 4.0 360.0 4.0 ... \n", "22 1991 4.0 4.0 360.0 4.0 ... \n", "23 1988 4.0 4.0 360.0 1.0 ... \n", "24 2002 1.0 1.0 90.0 1.0 ... \n", "25 1990 2.0 2.0 180.0 1.0 ... \n", "26 1990 2.0 2.0 180.0 3.0 ... \n", "27 2001 3.0 3.0 270.0 5.0 ... \n", "\n", " gk_passes_length_avg gk_goal_kicks gk_pct_goal_kicks_launched \\\n", "0 27.5 9.0 22.2 \n", "1 42.6 4.0 50.0 \n", "2 36.8 6.0 83.3 \n", "3 38.3 5.0 60.0 \n", "4 33.2 8.0 62.5 \n", "5 37.1 34.0 26.5 \n", "6 37.1 9.0 33.3 \n", "7 28.7 22.0 40.9 \n", "8 31.0 42.0 52.4 \n", "9 29.2 23.0 60.9 \n", "10 39.7 22.0 95.5 \n", "11 24.7 11.0 0.0 \n", "12 38.1 36.0 75.0 \n", "13 42.9 35.0 88.6 \n", "14 29.3 18.0 55.6 \n", "15 35.9 35.0 54.3 \n", "16 29.3 17.0 11.8 \n", "17 29.1 11.0 9.1 \n", "18 26.3 12.0 16.7 \n", "19 26.4 15.0 20.0 \n", "20 37.8 40.0 65.0 \n", "21 29.7 32.0 31.3 \n", "22 32.1 22.0 31.8 \n", "23 30.8 29.0 20.7 \n", "24 21.0 2.0 0.0 \n", "25 33.1 6.0 66.7 \n", "26 33.1 9.0 11.1 \n", "27 26.0 13.0 53.8 \n", "\n", " gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n", "0 27.0 23.0 1.0 \n", "1 50.3 10.0 2.0 \n", "2 69.2 13.0 1.0 \n", "3 45.8 18.0 0.0 \n", "4 49.4 15.0 0.0 \n", "5 28.1 46.0 2.0 \n", "6 34.6 9.0 0.0 \n", "7 40.3 45.0 2.0 \n", "8 38.7 54.0 2.0 \n", "9 47.0 52.0 12.0 \n", "10 62.5 75.0 8.0 \n", "11 20.4 27.0 1.0 \n", "12 61.3 33.0 3.0 \n", "13 62.7 54.0 1.0 \n", "14 46.1 28.0 2.0 \n", "15 43.6 63.0 4.0 \n", "16 22.1 34.0 2.0 \n", "17 18.9 26.0 2.0 \n", "18 29.6 18.0 0.0 \n", "19 27.9 48.0 2.0 \n", "20 50.0 62.0 4.0 \n", "21 35.4 49.0 0.0 \n", "22 34.2 57.0 2.0 \n", "23 28.3 41.0 2.0 \n", "24 23.0 8.0 1.0 \n", "25 52.0 33.0 1.0 \n", "26 25.0 16.0 1.0 \n", "27 41.7 33.0 2.0 \n", "\n", " gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n", "0 4.3 2.0 \n", "1 20.0 2.0 \n", "2 7.7 0.0 \n", "3 0.0 0.0 \n", "4 0.0 3.0 \n", "5 4.3 3.0 \n", "6 0.0 7.0 \n", "7 4.4 2.0 \n", "8 3.7 2.0 \n", "9 23.1 3.0 \n", "10 10.7 2.0 \n", "11 3.7 7.0 \n", "12 9.1 5.0 \n", "13 1.9 8.0 \n", "14 7.1 8.0 \n", "15 6.3 1.0 \n", "16 5.9 2.0 \n", "17 7.7 2.0 \n", "18 0.0 1.0 \n", "19 4.2 6.0 \n", "20 6.5 3.0 \n", "21 0.0 3.0 \n", "22 3.5 2.0 \n", "23 4.9 0.0 \n", "24 12.5 0.0 \n", "25 3.0 0.0 \n", "26 6.3 1.0 \n", "27 6.1 3.0 \n", "\n", " gk_def_actions_outside_pen_area_per90 gk_avg_distance_def_actions \n", "0 1.00 15.7 \n", "1 2.00 12.4 \n", "2 0.00 14.5 \n", "3 0.00 0.0 \n", "4 1.50 22.0 \n", "5 1.00 14.5 \n", "6 7.00 28.9 \n", "7 0.67 11.7 \n", "8 0.50 10.3 \n", "9 0.75 9.8 \n", "10 0.50 9.3 \n", "11 1.75 18.2 \n", "12 1.25 15.8 \n", "13 2.00 19.4 \n", "14 2.67 22.0 \n", "15 0.25 7.8 \n", "16 0.50 12.2 \n", "17 1.00 15.0 \n", "18 1.00 21.0 \n", "19 1.50 15.7 \n", "20 0.75 12.5 \n", "21 0.75 14.0 \n", "22 0.50 11.5 \n", "23 0.00 6.5 \n", "24 0.00 9.0 \n", "25 0.00 9.6 \n", "26 0.50 13.7 \n", "27 1.00 16.3 \n", "\n", "[28 rows x 47 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_keeper = get_keeper_data('https://fbref.com/en/comps/11/','/Serie-A-Stats')\n", "\n", "df_keeper.to_csv('fbref_data/keepers_players.csv', index=False)\n", "\n", "df_keeper" ] }, { "cell_type": "code", "execution_count": 5, "id": "b9924851", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
teamplayers_usedpossessiongamesgames_startsminutesgoalsassistspens_madepens_att...foulsfouledoffsidespens_wonpens_concededown_goalsball_recoveriesaerials_wonaerials_lostaerials_won_pct
0Atalanta23.049.54.044.0360.08.08.00.00.0...48.034.09.00.00.00.0232.060.065.048.0
1Bologna22.056.54.044.0360.03.02.00.01.0...42.041.04.00.00.00.0205.046.034.057.5
2Cagliari21.037.84.044.0360.01.01.00.00.0...46.035.07.00.01.00.0241.051.060.045.9
3Empoli27.047.84.044.0360.00.00.00.00.0...43.059.07.00.02.01.0176.039.054.041.9
4Fiorentina22.061.04.044.0360.09.07.00.00.0...49.052.04.00.01.00.0196.053.056.048.6
5Frosinone23.048.34.044.0360.07.04.02.02.0...43.049.011.02.00.00.0202.052.053.049.5
6Genoa19.033.34.044.0360.04.03.00.00.0...51.035.05.00.00.00.0177.060.046.056.6
7Hellas Verona21.043.54.044.0360.04.02.00.00.0...66.046.012.00.01.00.0207.082.071.053.6
8Inter19.048.84.044.0360.013.011.02.02.0...47.045.05.02.00.00.0187.044.030.059.5
9Juventus21.048.84.044.0360.09.07.01.02.0...51.048.010.01.00.00.0181.038.026.059.4
10Lazio20.056.04.044.0360.04.04.00.00.0...47.046.04.00.00.00.0188.030.051.037.0
11Lecce19.043.54.044.0360.07.05.02.02.0...55.062.03.01.00.00.0191.054.043.055.7
12Milan19.055.34.044.0360.09.06.03.03.0...45.053.06.02.01.00.0169.033.042.044.0
13Monza22.056.84.044.0360.03.03.00.00.0...53.035.05.00.01.00.0175.037.045.045.1
14Napoli19.061.84.044.0360.08.05.01.02.0...42.039.014.01.01.00.0208.047.035.057.3
15Roma23.057.04.044.0360.010.08.01.01.0...53.045.07.00.01.00.0196.076.054.058.5
16Salernitana21.051.54.044.0360.03.03.00.00.0...48.062.05.00.01.00.0183.054.086.038.6
17Sassuolo24.043.54.044.0360.05.04.01.01.0...36.041.03.01.03.00.0171.037.050.042.5
18Torino22.051.34.044.0360.05.03.00.00.0...53.043.010.00.02.00.0193.059.063.048.4
19Udinese22.048.54.044.0360.01.01.00.00.0...56.042.05.00.01.00.0203.064.052.055.2
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 Atalanta 23.0 49.5 4.0 44.0 360.0 \n", "1 Bologna 22.0 56.5 4.0 44.0 360.0 \n", "2 Cagliari 21.0 37.8 4.0 44.0 360.0 \n", "3 Empoli 27.0 47.8 4.0 44.0 360.0 \n", "4 Fiorentina 22.0 61.0 4.0 44.0 360.0 \n", "5 Frosinone 23.0 48.3 4.0 44.0 360.0 \n", "6 Genoa 19.0 33.3 4.0 44.0 360.0 \n", "7 Hellas Verona 21.0 43.5 4.0 44.0 360.0 \n", "8 Inter 19.0 48.8 4.0 44.0 360.0 \n", "9 Juventus 21.0 48.8 4.0 44.0 360.0 \n", "10 Lazio 20.0 56.0 4.0 44.0 360.0 \n", "11 Lecce 19.0 43.5 4.0 44.0 360.0 \n", "12 Milan 19.0 55.3 4.0 44.0 360.0 \n", "13 Monza 22.0 56.8 4.0 44.0 360.0 \n", "14 Napoli 19.0 61.8 4.0 44.0 360.0 \n", "15 Roma 23.0 57.0 4.0 44.0 360.0 \n", "16 Salernitana 21.0 51.5 4.0 44.0 360.0 \n", "17 Sassuolo 24.0 43.5 4.0 44.0 360.0 \n", "18 Torino 22.0 51.3 4.0 44.0 360.0 \n", "19 Udinese 22.0 48.5 4.0 44.0 360.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 8.0 8.0 0.0 0.0 ... 48.0 34.0 9.0 \n", "1 3.0 2.0 0.0 1.0 ... 42.0 41.0 4.0 \n", "2 1.0 1.0 0.0 0.0 ... 46.0 35.0 7.0 \n", "3 0.0 0.0 0.0 0.0 ... 43.0 59.0 7.0 \n", "4 9.0 7.0 0.0 0.0 ... 49.0 52.0 4.0 \n", "5 7.0 4.0 2.0 2.0 ... 43.0 49.0 11.0 \n", "6 4.0 3.0 0.0 0.0 ... 51.0 35.0 5.0 \n", "7 4.0 2.0 0.0 0.0 ... 66.0 46.0 12.0 \n", "8 13.0 11.0 2.0 2.0 ... 47.0 45.0 5.0 \n", "9 9.0 7.0 1.0 2.0 ... 51.0 48.0 10.0 \n", "10 4.0 4.0 0.0 0.0 ... 47.0 46.0 4.0 \n", "11 7.0 5.0 2.0 2.0 ... 55.0 62.0 3.0 \n", "12 9.0 6.0 3.0 3.0 ... 45.0 53.0 6.0 \n", "13 3.0 3.0 0.0 0.0 ... 53.0 35.0 5.0 \n", "14 8.0 5.0 1.0 2.0 ... 42.0 39.0 14.0 \n", "15 10.0 8.0 1.0 1.0 ... 53.0 45.0 7.0 \n", "16 3.0 3.0 0.0 0.0 ... 48.0 62.0 5.0 \n", "17 5.0 4.0 1.0 1.0 ... 36.0 41.0 3.0 \n", "18 5.0 3.0 0.0 0.0 ... 53.0 43.0 10.0 \n", "19 1.0 1.0 0.0 0.0 ... 56.0 42.0 5.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 232.0 60.0 \n", "1 0.0 0.0 0.0 205.0 46.0 \n", "2 0.0 1.0 0.0 241.0 51.0 \n", "3 0.0 2.0 1.0 176.0 39.0 \n", "4 0.0 1.0 0.0 196.0 53.0 \n", "5 2.0 0.0 0.0 202.0 52.0 \n", "6 0.0 0.0 0.0 177.0 60.0 \n", "7 0.0 1.0 0.0 207.0 82.0 \n", "8 2.0 0.0 0.0 187.0 44.0 \n", "9 1.0 0.0 0.0 181.0 38.0 \n", "10 0.0 0.0 0.0 188.0 30.0 \n", "11 1.0 0.0 0.0 191.0 54.0 \n", "12 2.0 1.0 0.0 169.0 33.0 \n", "13 0.0 1.0 0.0 175.0 37.0 \n", "14 1.0 1.0 0.0 208.0 47.0 \n", "15 0.0 1.0 0.0 196.0 76.0 \n", "16 0.0 1.0 0.0 183.0 54.0 \n", "17 1.0 3.0 0.0 171.0 37.0 \n", "18 0.0 2.0 0.0 193.0 59.0 \n", "19 0.0 1.0 0.0 203.0 64.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 65.0 48.0 \n", "1 34.0 57.5 \n", "2 60.0 45.9 \n", "3 54.0 41.9 \n", "4 56.0 48.6 \n", "5 53.0 49.5 \n", "6 46.0 56.6 \n", "7 71.0 53.6 \n", "8 30.0 59.5 \n", "9 26.0 59.4 \n", "10 51.0 37.0 \n", "11 43.0 55.7 \n", "12 42.0 44.0 \n", "13 45.0 45.1 \n", "14 35.0 57.3 \n", "15 54.0 58.5 \n", "16 86.0 38.6 \n", "17 50.0 42.5 \n", "18 63.0 48.4 \n", "19 52.0 55.2 \n", "\n", "[20 rows x 152 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_team = get_team_data('https://fbref.com/en/comps/11/','/Serie-A-Stats', 'for')\n", "\n", "df_team.to_csv('fbref_data/teams.csv', index=False)\n", "\n", "df_team" ] }, { "cell_type": "code", "execution_count": 6, "id": "5868ec4a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
teamplayers_usedpossessiongamesgames_startsminutesgoalsassistspens_madepens_att...foulsfouledoffsidespens_wonpens_concededown_goalsball_recoveriesaerials_wonaerials_lostaerials_won_pct
0vs Atalanta23.050.54.044.0360.05.04.00.00.0...36.047.02.00.00.00.0212.065.060.052.0
1vs Bologna22.043.54.044.0360.04.04.00.00.0...50.040.012.00.01.00.0207.034.046.042.5
2vs Cagliari21.062.34.044.0360.04.03.00.01.0...38.041.05.00.00.00.0220.060.051.054.1
3vs Empoli27.052.34.044.0360.011.08.01.02.0...60.042.08.01.00.00.0203.054.039.058.1
4vs Fiorentina22.039.04.044.0360.09.08.01.01.0...56.043.05.01.00.00.0202.056.053.051.4
5vs Frosinone23.051.84.044.0360.06.05.00.00.0...50.039.06.00.02.00.0212.053.052.050.5
6vs Genoa19.066.84.044.0360.07.06.00.00.0...43.043.09.00.00.00.0200.046.060.043.4
7vs Hellas Verona21.056.54.044.0360.04.02.01.01.0...47.063.07.01.00.00.0190.071.082.046.4
8vs Inter19.051.34.044.0360.01.01.00.00.0...47.044.05.00.02.00.0163.030.044.040.5
9vs Juventus21.051.34.044.0360.02.02.00.00.0...52.049.05.00.02.00.0173.026.038.040.6
10vs Lazio20.044.04.044.0360.07.05.00.00.0...49.044.07.00.00.00.0196.051.030.063.0
11vs Lecce19.056.54.044.0360.04.04.00.00.0...64.053.05.00.02.00.0203.043.054.044.3
12vs Milan19.044.84.044.0360.07.06.01.01.0...56.043.07.01.03.00.0176.042.033.056.0
13vs Monza22.043.34.044.0360.06.05.01.01.0...37.052.06.01.00.00.0187.045.037.054.9
14vs Napoli19.038.34.044.0360.05.04.01.01.0...47.039.07.01.02.00.0173.035.047.042.7
15vs Roma23.043.04.044.0360.06.04.01.01.0...46.051.04.01.01.01.0159.054.076.041.5
16vs Salernitana21.048.54.044.0360.08.05.01.01.0...64.046.04.00.00.00.0203.086.054.061.4
17vs Sassuolo24.056.54.044.0360.09.06.02.03.0...45.034.015.02.01.00.0207.050.037.057.5
18vs Torino22.048.84.044.0360.04.02.02.02.0...44.048.07.01.00.00.0207.063.059.051.6
19vs Udinese22.051.54.044.0360.04.03.01.01.0...43.051.010.00.00.00.0188.052.064.044.8
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 vs Atalanta 23.0 50.5 4.0 44.0 360.0 \n", "1 vs Bologna 22.0 43.5 4.0 44.0 360.0 \n", "2 vs Cagliari 21.0 62.3 4.0 44.0 360.0 \n", "3 vs Empoli 27.0 52.3 4.0 44.0 360.0 \n", "4 vs Fiorentina 22.0 39.0 4.0 44.0 360.0 \n", "5 vs Frosinone 23.0 51.8 4.0 44.0 360.0 \n", "6 vs Genoa 19.0 66.8 4.0 44.0 360.0 \n", "7 vs Hellas Verona 21.0 56.5 4.0 44.0 360.0 \n", "8 vs Inter 19.0 51.3 4.0 44.0 360.0 \n", "9 vs Juventus 21.0 51.3 4.0 44.0 360.0 \n", "10 vs Lazio 20.0 44.0 4.0 44.0 360.0 \n", "11 vs Lecce 19.0 56.5 4.0 44.0 360.0 \n", "12 vs Milan 19.0 44.8 4.0 44.0 360.0 \n", "13 vs Monza 22.0 43.3 4.0 44.0 360.0 \n", "14 vs Napoli 19.0 38.3 4.0 44.0 360.0 \n", "15 vs Roma 23.0 43.0 4.0 44.0 360.0 \n", "16 vs Salernitana 21.0 48.5 4.0 44.0 360.0 \n", "17 vs Sassuolo 24.0 56.5 4.0 44.0 360.0 \n", "18 vs Torino 22.0 48.8 4.0 44.0 360.0 \n", "19 vs Udinese 22.0 51.5 4.0 44.0 360.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 5.0 4.0 0.0 0.0 ... 36.0 47.0 2.0 \n", "1 4.0 4.0 0.0 0.0 ... 50.0 40.0 12.0 \n", "2 4.0 3.0 0.0 1.0 ... 38.0 41.0 5.0 \n", "3 11.0 8.0 1.0 2.0 ... 60.0 42.0 8.0 \n", "4 9.0 8.0 1.0 1.0 ... 56.0 43.0 5.0 \n", "5 6.0 5.0 0.0 0.0 ... 50.0 39.0 6.0 \n", "6 7.0 6.0 0.0 0.0 ... 43.0 43.0 9.0 \n", "7 4.0 2.0 1.0 1.0 ... 47.0 63.0 7.0 \n", "8 1.0 1.0 0.0 0.0 ... 47.0 44.0 5.0 \n", "9 2.0 2.0 0.0 0.0 ... 52.0 49.0 5.0 \n", "10 7.0 5.0 0.0 0.0 ... 49.0 44.0 7.0 \n", "11 4.0 4.0 0.0 0.0 ... 64.0 53.0 5.0 \n", "12 7.0 6.0 1.0 1.0 ... 56.0 43.0 7.0 \n", "13 6.0 5.0 1.0 1.0 ... 37.0 52.0 6.0 \n", "14 5.0 4.0 1.0 1.0 ... 47.0 39.0 7.0 \n", "15 6.0 4.0 1.0 1.0 ... 46.0 51.0 4.0 \n", "16 8.0 5.0 1.0 1.0 ... 64.0 46.0 4.0 \n", "17 9.0 6.0 2.0 3.0 ... 45.0 34.0 15.0 \n", "18 4.0 2.0 2.0 2.0 ... 44.0 48.0 7.0 \n", "19 4.0 3.0 1.0 1.0 ... 43.0 51.0 10.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 212.0 65.0 \n", "1 0.0 1.0 0.0 207.0 34.0 \n", "2 0.0 0.0 0.0 220.0 60.0 \n", "3 1.0 0.0 0.0 203.0 54.0 \n", "4 1.0 0.0 0.0 202.0 56.0 \n", "5 0.0 2.0 0.0 212.0 53.0 \n", "6 0.0 0.0 0.0 200.0 46.0 \n", "7 1.0 0.0 0.0 190.0 71.0 \n", "8 0.0 2.0 0.0 163.0 30.0 \n", "9 0.0 2.0 0.0 173.0 26.0 \n", "10 0.0 0.0 0.0 196.0 51.0 \n", "11 0.0 2.0 0.0 203.0 43.0 \n", "12 1.0 3.0 0.0 176.0 42.0 \n", "13 1.0 0.0 0.0 187.0 45.0 \n", "14 1.0 2.0 0.0 173.0 35.0 \n", "15 1.0 1.0 1.0 159.0 54.0 \n", "16 0.0 0.0 0.0 203.0 86.0 \n", "17 2.0 1.0 0.0 207.0 50.0 \n", "18 1.0 0.0 0.0 207.0 63.0 \n", "19 0.0 0.0 0.0 188.0 52.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 60.0 52.0 \n", "1 46.0 42.5 \n", "2 51.0 54.1 \n", "3 39.0 58.1 \n", "4 53.0 51.4 \n", "5 52.0 50.5 \n", "6 60.0 43.4 \n", "7 82.0 46.4 \n", "8 44.0 40.5 \n", "9 38.0 40.6 \n", "10 30.0 63.0 \n", "11 54.0 44.3 \n", "12 33.0 56.0 \n", "13 37.0 54.9 \n", "14 47.0 42.7 \n", "15 76.0 41.5 \n", "16 54.0 61.4 \n", "17 37.0 57.5 \n", "18 59.0 51.6 \n", "19 64.0 44.8 \n", "\n", "[20 rows x 152 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_vsteam = get_team_data('https://fbref.com/en/comps/11/','/Serie-A-Stats', 'vs')\n", "\n", "df_vsteam.to_csv('fbref_data/teams_vs.csv', index=False)\n", "\n", "df_vsteam" ] }, { "cell_type": "code", "execution_count": 7, "id": "11e51337", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Outfield player columns\n", "['player' 'nationality' 'position' 'team' 'age' 'birth_year' 'games'\n", " 'games_starts' 'minutes' 'goals' 'assists' 'pens_made' 'pens_att'\n", " 'cards_yellow' 'cards_red' 'goals_per90' 'assists_per90'\n", " 'goals_assists_per90' 'goals_pens_per90' 'goals_assists_pens_per90' 'xg'\n", " 'npxg' 'xg_per90' 'npxg_per90' 'minutes_90s' 'shots_on_target'\n", " 'shots_free_kicks' 'shots_on_target_pct' 'shots_on_target_per90'\n", " 'goals_per_shot' 'goals_per_shot_on_target' 'npxg_per_shot' 'xg_net'\n", " 'npxg_net' 'passes_completed' 'passes' 'passes_pct'\n", " 'passes_total_distance' 'passes_progressive_distance'\n", " 'passes_completed_short' 'passes_short' 'passes_pct_short'\n", " 'passes_completed_medium' 'passes_medium' 'passes_pct_medium'\n", " 'passes_completed_long' 'passes_long' 'passes_pct_long' 'assisted_shots'\n", " 'passes_into_final_third' 'passes_into_penalty_area'\n", " 'crosses_into_penalty_area' 'progressive_passes' 'passes_live'\n", " 'passes_dead' 'passes_free_kicks' 'through_balls' 'passes_switches'\n", " 'crosses' 'corner_kicks' 'corner_kicks_in' 'corner_kicks_out'\n", " 'corner_kicks_straight' 'throw_ins' 'passes_offsides' 'passes_blocked'\n", " 'sca' 'sca_per90' 'sca_passes_live' 'sca_passes_dead' 'sca_shots'\n", " 'sca_fouled' 'gca' 'gca_per90' 'gca_passes_live' 'gca_passes_dead'\n", " 'gca_shots' 'gca_fouled' 'gca_defense' 'tackles' 'tackles_won'\n", " 'tackles_def_3rd' 'tackles_mid_3rd' 'tackles_att_3rd' 'blocks'\n", " 'blocked_shots' 'blocked_passes' 'interceptions' 'clearances' 'errors'\n", " 'touches' 'touches_def_pen_area' 'touches_def_3rd' 'touches_mid_3rd'\n", " 'touches_att_3rd' 'touches_att_pen_area' 'touches_live_ball' 'carries'\n", " 'progressive_carries' 'carries_into_final_third'\n", " 'carries_into_penalty_area' 'passes_received' 'miscontrols'\n", " 'dispossessed' 'cards_yellow_red' 'fouls' 'fouled' 'offsides' 'pens_won'\n", " 'pens_conceded' 'own_goals' 'ball_recoveries' 'aerials_won'\n", " 'aerials_lost' 'aerials_won_pct']\n", "Keeper player columns\n", "['player' 'nationality' 'position' 'team' 'age' 'birth_year' 'gk_games'\n", " 'gk_games_starts' 'gk_minutes' 'gk_goals_against'\n", " 'gk_goals_against_per90' 'gk_shots_on_target_against' 'gk_saves'\n", " 'gk_save_pct' 'gk_wins' 'gk_ties' 'gk_losses' 'gk_clean_sheets'\n", " 'gk_clean_sheets_pct' 'gk_pens_att' 'gk_pens_allowed' 'gk_pens_saved'\n", " 'gk_pens_missed' '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' 'gk_psxg_net_per90'\n", " 'gk_passes_completed_launched' 'gk_passes_launched'\n", " 'gk_passes_pct_launched' 'gk_passes' 'gk_passes_throws'\n", " 'gk_pct_passes_launched' 'gk_passes_length_avg' 'gk_goal_kicks'\n", " 'gk_pct_goal_kicks_launched' 'gk_goal_kick_length_avg' 'gk_crosses'\n", " 'gk_crosses_stopped' 'gk_crosses_stopped_pct'\n", " 'gk_def_actions_outside_pen_area' 'gk_def_actions_outside_pen_area_per90'\n", " 'gk_avg_distance_def_actions']\n", "Team columns\n", "['team' 'players_used' 'possession' 'games' 'games_starts' 'minutes'\n", " 'goals' 'assists' 'pens_made' 'pens_att' 'cards_yellow' 'cards_red'\n", " 'goals_per90' 'assists_per90' 'goals_assists_per90' 'goals_pens_per90'\n", " 'goals_assists_pens_per90' 'xg' 'npxg' 'xg_per90' 'npxg_per90' 'gk_games'\n", " 'gk_games_starts' 'gk_minutes' 'gk_goals_against'\n", " 'gk_goals_against_per90' 'gk_shots_on_target_against' 'gk_saves'\n", " 'gk_save_pct' 'gk_wins' 'gk_ties' 'gk_losses' 'gk_clean_sheets'\n", " 'gk_clean_sheets_pct' 'gk_pens_att' 'gk_pens_allowed' 'gk_pens_saved'\n", " 'gk_pens_missed' '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' 'gk_psxg_net_per90'\n", " 'gk_passes_completed_launched' 'gk_passes_launched'\n", " 'gk_passes_pct_launched' 'gk_passes' 'gk_passes_throws'\n", " 'gk_pct_passes_launched' 'gk_passes_length_avg' 'gk_goal_kicks'\n", " 'gk_pct_goal_kicks_launched' 'gk_goal_kick_length_avg' 'gk_crosses'\n", " 'gk_crosses_stopped' 'gk_crosses_stopped_pct'\n", " 'gk_def_actions_outside_pen_area' 'gk_def_actions_outside_pen_area_per90'\n", " 'gk_avg_distance_def_actions' 'shots_on_target' 'shots_free_kicks'\n", " 'shots_on_target_pct' 'shots_on_target_per90' 'goals_per_shot'\n", " 'goals_per_shot_on_target' 'npxg_per_shot' 'xg_net' 'npxg_net'\n", " 'passes_completed' 'passes' 'passes_pct' 'passes_total_distance'\n", " 'passes_progressive_distance' 'passes_completed_short' 'passes_short'\n", " 'passes_pct_short' 'passes_completed_medium' 'passes_medium'\n", " 'passes_pct_medium' 'passes_completed_long' 'passes_long'\n", " 'passes_pct_long' 'assisted_shots' 'passes_into_final_third'\n", " 'passes_into_penalty_area' 'crosses_into_penalty_area'\n", " 'progressive_passes' 'passes_live' 'passes_dead' 'passes_free_kicks'\n", " 'through_balls' 'passes_switches' 'crosses' 'corner_kicks'\n", " 'corner_kicks_in' 'corner_kicks_out' 'corner_kicks_straight' 'throw_ins'\n", " 'passes_offsides' 'passes_blocked' 'sca' 'sca_per90' 'sca_passes_live'\n", " 'sca_passes_dead' 'sca_shots' 'sca_fouled' 'gca' 'gca_per90'\n", " 'gca_passes_live' 'gca_passes_dead' 'gca_shots' 'gca_fouled'\n", " 'gca_defense' 'tackles' 'tackles_won' 'tackles_def_3rd' 'tackles_mid_3rd'\n", " 'tackles_att_3rd' 'blocks' 'blocked_shots' 'blocked_passes'\n", " 'interceptions' 'clearances' 'errors' 'touches' 'touches_def_pen_area'\n", " 'touches_def_3rd' 'touches_mid_3rd' 'touches_att_3rd'\n", " 'touches_att_pen_area' 'touches_live_ball' 'carries'\n", " 'progressive_carries' 'carries_into_final_third'\n", " 'carries_into_penalty_area' 'passes_received' 'miscontrols'\n", " 'dispossessed' 'cards_yellow_red' 'fouls' 'fouled' 'offsides' 'pens_won'\n", " 'pens_conceded' 'own_goals' 'ball_recoveries' 'aerials_won'\n", " 'aerials_lost' 'aerials_won_pct']\n", "Vs Team columns\n", "['team' 'players_used' 'possession' 'games' 'games_starts' 'minutes'\n", " 'goals' 'assists' 'pens_made' 'pens_att' 'cards_yellow' 'cards_red'\n", " 'goals_per90' 'assists_per90' 'goals_assists_per90' 'goals_pens_per90'\n", " 'goals_assists_pens_per90' 'xg' 'npxg' 'xg_per90' 'npxg_per90' 'gk_games'\n", " 'gk_games_starts' 'gk_minutes' 'gk_goals_against'\n", " 'gk_goals_against_per90' 'gk_shots_on_target_against' 'gk_saves'\n", " 'gk_save_pct' 'gk_wins' 'gk_ties' 'gk_losses' 'gk_clean_sheets'\n", " 'gk_clean_sheets_pct' 'gk_pens_att' 'gk_pens_allowed' 'gk_pens_saved'\n", " 'gk_pens_missed' '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' 'gk_psxg_net_per90'\n", " 'gk_passes_completed_launched' 'gk_passes_launched'\n", " 'gk_passes_pct_launched' 'gk_passes' 'gk_passes_throws'\n", " 'gk_pct_passes_launched' 'gk_passes_length_avg' 'gk_goal_kicks'\n", " 'gk_pct_goal_kicks_launched' 'gk_goal_kick_length_avg' 'gk_crosses'\n", " 'gk_crosses_stopped' 'gk_crosses_stopped_pct'\n", " 'gk_def_actions_outside_pen_area' 'gk_def_actions_outside_pen_area_per90'\n", " 'gk_avg_distance_def_actions' 'shots_on_target' 'shots_free_kicks'\n", " 'shots_on_target_pct' 'shots_on_target_per90' 'goals_per_shot'\n", " 'goals_per_shot_on_target' 'npxg_per_shot' 'xg_net' 'npxg_net'\n", " 'passes_completed' 'passes' 'passes_pct' 'passes_total_distance'\n", " 'passes_progressive_distance' 'passes_completed_short' 'passes_short'\n", " 'passes_pct_short' 'passes_completed_medium' 'passes_medium'\n", " 'passes_pct_medium' 'passes_completed_long' 'passes_long'\n", " 'passes_pct_long' 'assisted_shots' 'passes_into_final_third'\n", " 'passes_into_penalty_area' 'crosses_into_penalty_area'\n", " 'progressive_passes' 'passes_live' 'passes_dead' 'passes_free_kicks'\n", " 'through_balls' 'passes_switches' 'crosses' 'corner_kicks'\n", " 'corner_kicks_in' 'corner_kicks_out' 'corner_kicks_straight' 'throw_ins'\n", " 'passes_offsides' 'passes_blocked' 'sca' 'sca_per90' 'sca_passes_live'\n", " 'sca_passes_dead' 'sca_shots' 'sca_fouled' 'gca' 'gca_per90'\n", " 'gca_passes_live' 'gca_passes_dead' 'gca_shots' 'gca_fouled'\n", " 'gca_defense' 'tackles' 'tackles_won' 'tackles_def_3rd' 'tackles_mid_3rd'\n", " 'tackles_att_3rd' 'blocks' 'blocked_shots' 'blocked_passes'\n", " 'interceptions' 'clearances' 'errors' 'touches' 'touches_def_pen_area'\n", " 'touches_def_3rd' 'touches_mid_3rd' 'touches_att_3rd'\n", " 'touches_att_pen_area' 'touches_live_ball' 'carries'\n", " 'progressive_carries' 'carries_into_final_third'\n", " 'carries_into_penalty_area' 'passes_received' 'miscontrols'\n", " 'dispossessed' 'cards_yellow_red' 'fouls' 'fouled' 'offsides' 'pens_won'\n", " 'pens_conceded' 'own_goals' 'ball_recoveries' 'aerials_won'\n", " 'aerials_lost' 'aerials_won_pct']\n" ] } ], "source": [ "print('Outfield player columns')\n", "print(df_outfield.columns.values)\n", "\n", "print('Keeper player columns')\n", "print(df_keeper.columns.values)\n", "\n", "print('Team columns')\n", "print(df_team.columns.values)\n", "\n", "print('Vs Team columns')\n", "print(df_team.columns.values)" ] }, { "cell_type": "markdown", "id": "e4f13ae2", "metadata": {}, "source": [ "Scrape data for past seasons. \n", "\n", "Do not repeat if data is already present." ] }, { "cell_type": "code", "execution_count": 16, "id": "22ad9be5", "metadata": {}, "outputs": [], "source": [ "old_season = ['2020-2021', '2021-2022', '2022-2023']\n", "#old_season = ['2022-2023']\n", "\n", "for s in old_season:\n", " comp = 'https://fbref.com/en/comps/11/' + s + '/'\n", " statstr = '/' + s + '-Serie-A-Stats'\n", " \n", " season_short = s[2:4] + s[7:9]\n", " \n", " df_outfield = get_outfield_data(comp, statstr)\n", " df_outfield.to_csv('fbref_data/season' + season_short + '/outfield_players.csv', index=False)\n", "\n", " df_keeper = get_keeper_data(comp, statstr)\n", " df_keeper.to_csv('fbref_data/season' + season_short + '/keepers_players.csv', index=False)\n", "\n", " df_team = get_team_data(comp, statstr, 'for')\n", " df_team.to_csv('fbref_data/season' + season_short + '/teams.csv', index=False)\n", "\n", " df_vsteam = get_team_data(comp, statstr, 'vs')\n", " df_vsteam.to_csv('fbref_data/season' + season_short + '/teams_vs.csv', index=False)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d37abd7f", "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 }