{ "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-23219883.03.0270.00.0...3.04.00.00.00.00.015.010.02.083.3
1Yacine Adlifr FRAMFMilan23-06320001.01.057.00.0...0.00.00.00.00.00.05.00.01.00.0
2Michel Aebischerch SUIMFBologna26-26719976.06.0527.00.0...10.06.00.00.00.00.029.04.06.040.0
3Jean-Daniel Akpa-Akproci CIVMFMonza30-35419921.00.07.00.0...0.00.00.00.00.00.01.00.00.00.0
4Luis Albertoes ESPMFLazio31-00219926.06.0540.02.0...6.08.00.00.00.00.036.03.05.037.5
..................................................................
453Joshua Zirkzeenl NEDFWBologna22-13120016.06.0520.01.0...5.01.02.00.00.00.015.012.03.080.0
454Zitoao ANGFWCagliari21-20520026.05.0477.02.0...5.012.06.00.00.00.09.02.07.022.2
455Nadir Zorteait ITADFAtalanta24-10319993.00.096.01.0...3.00.00.00.00.00.04.00.01.00.0
456Milan Đurićba BIHFW,MFHellas Verona33-13119905.01.0154.00.0...7.01.02.00.00.00.04.023.015.060.5
457Mateusz Łęgowskipl POLMFSalernitana20-24420035.02.0167.00.0...3.03.00.00.00.00.016.04.05.044.4
\n", "

458 rows × 115 columns

\n", "
" ], "text/plain": [ " player nationality position team age \\\n", "0 Francesco Acerbi it ITA DF Inter 35-232 \n", "1 Yacine Adli fr FRA MF Milan 23-063 \n", "2 Michel Aebischer ch SUI MF Bologna 26-267 \n", "3 Jean-Daniel Akpa-Akpro ci CIV MF Monza 30-354 \n", "4 Luis Alberto es ESP MF Lazio 31-002 \n", ".. ... ... ... ... ... \n", "453 Joshua Zirkzee nl NED FW Bologna 22-131 \n", "454 Zito ao ANG FW Cagliari 21-205 \n", "455 Nadir Zortea it ITA DF Atalanta 24-103 \n", "456 Milan Đurić ba BIH FW,MF Hellas Verona 33-131 \n", "457 Mateusz Łęgowski pl POL MF Salernitana 20-244 \n", "\n", " birth_year games games_starts minutes goals ... fouls fouled \\\n", "0 1988 3.0 3.0 270.0 0.0 ... 3.0 4.0 \n", "1 2000 1.0 1.0 57.0 0.0 ... 0.0 0.0 \n", "2 1997 6.0 6.0 527.0 0.0 ... 10.0 6.0 \n", "3 1992 1.0 0.0 7.0 0.0 ... 0.0 0.0 \n", "4 1992 6.0 6.0 540.0 2.0 ... 6.0 8.0 \n", ".. ... ... ... ... ... ... ... ... \n", "453 2001 6.0 6.0 520.0 1.0 ... 5.0 1.0 \n", "454 2002 6.0 5.0 477.0 2.0 ... 5.0 12.0 \n", "455 1999 3.0 0.0 96.0 1.0 ... 3.0 0.0 \n", "456 1990 5.0 1.0 154.0 0.0 ... 7.0 1.0 \n", "457 2003 5.0 2.0 167.0 0.0 ... 3.0 3.0 \n", "\n", " offsides pens_won pens_conceded own_goals ball_recoveries \\\n", "0 0.0 0.0 0.0 0.0 15.0 \n", "1 0.0 0.0 0.0 0.0 5.0 \n", "2 0.0 0.0 0.0 0.0 29.0 \n", "3 0.0 0.0 0.0 0.0 1.0 \n", "4 0.0 0.0 0.0 0.0 36.0 \n", ".. ... ... ... ... ... \n", "453 2.0 0.0 0.0 0.0 15.0 \n", "454 6.0 0.0 0.0 0.0 9.0 \n", "455 0.0 0.0 0.0 0.0 4.0 \n", "456 2.0 0.0 0.0 0.0 4.0 \n", "457 0.0 0.0 0.0 0.0 16.0 \n", "\n", " aerials_won aerials_lost aerials_won_pct \n", "0 10.0 2.0 83.3 \n", "1 0.0 1.0 0.0 \n", "2 4.0 6.0 40.0 \n", "3 0.0 0.0 0.0 \n", "4 3.0 5.0 37.5 \n", ".. ... ... ... \n", "453 12.0 3.0 80.0 \n", "454 2.0 7.0 22.2 \n", "455 0.0 1.0 0.0 \n", "456 23.0 15.0 60.5 \n", "457 4.0 5.0 44.4 \n", "\n", "[458 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", " \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-20419894.04.0360.010.0...32.124.058.344.050.02.04.03.00.7512.7
1Elia Caprileit ITAGKEmpoli22-03620011.01.090.01.0...42.64.050.050.310.02.020.02.02.0012.4
2Marco Carnesecchiit ITAGKAtalanta23-09120002.02.0180.03.0...38.215.080.060.730.03.010.00.00.0011.2
3Michele Cerofoliniit ITAGKFrosinone24-26919991.01.090.01.0...38.35.060.045.818.00.00.00.00.000.0
4Oliver Christensendk DENGKFiorentina24-19219992.02.0180.06.0...33.28.062.549.415.00.00.03.01.5022.0
5Andrea Consigliit ITAGKSassuolo36-24619874.04.0360.06.0...39.442.026.228.373.04.05.53.00.7513.1
6Alessio Cragnoit ITAGKSassuolo29-09419942.02.0180.06.0...41.219.026.329.426.00.00.07.03.5028.9
7Michele Di Gregorioit ITAGKMonza26-06519975.05.0450.06.0...30.434.052.947.573.02.02.72.00.4010.5
8Wladimiro Falconeit ITAGKLecce28-17119956.06.0540.05.0...30.955.047.336.380.03.03.83.00.509.6
9Mike Maignanfr FRAGKMilan28-08919954.04.0360.07.0...29.223.060.947.052.012.023.13.00.759.8
10Josep Martinezes ESPGKGenoa25-12619986.06.0540.09.0...39.137.094.662.1113.012.010.62.00.338.5
11Alex Meretit ITAGKNapoli26-19219976.06.0540.06.0...24.121.00.020.553.01.01.98.01.3317.2
12Vanja Milinković-Savićrs SRBGKTorino26-22219976.06.0540.07.0...35.650.080.062.947.04.08.59.01.5017.5
13Lorenzo Montipòit ITAGKHellas Verona27-22219966.06.0540.06.0...45.250.084.061.572.01.01.412.02.0020.0
14Juan Mussoar ARGGKAtalanta29-14719944.04.0360.02.0...29.028.064.348.943.04.09.312.03.0019.9
15Guillermo Ochoamx MEXGKSalernitana38-07919856.06.0540.010.0...35.647.046.839.988.04.04.53.00.5013.5
16Rui Patríciopt PORGKRoma35-22719886.06.0540.011.0...27.531.019.424.262.02.03.23.00.5013.7
17Mattia Perinit ITAGKJuventus30-32419922.02.0180.01.0...29.111.09.118.926.02.07.72.01.0015.0
18Samuele Perisanit ITAGKEmpoli26-04019971.01.090.02.0...26.312.016.729.618.00.00.01.01.0021.0
19Ivan Provedelit ITAGKLazio29-19719946.06.0540.08.0...28.829.027.632.363.03.04.87.01.1716.0
20Boris Radunovićrs SRBGKCagliari27-12719966.06.0540.09.0...38.557.054.445.187.05.05.74.00.6711.9
21Marco Silvestriit ITAGKUdinese32-21219916.06.0540.010.0...30.245.026.732.869.01.01.43.00.5013.6
22Łukasz Skorupskipl POLGKBologna32-14819916.06.0540.04.0...31.134.029.433.689.03.03.42.00.3310.3
23Yann Sommerch SUIGKInter34-28719886.06.0540.03.0...29.739.020.527.359.05.08.52.00.339.6
24Alessandro Sorrentinoit ITAGKMonza21-18020021.01.090.01.0...21.02.00.023.08.01.012.50.00.009.0
25Marco Sportielloit ITAGKMilan31-14319922.02.0180.01.0...28.02.00.028.528.02.07.12.01.0013.2
26Wojciech Szczęsnypl POLGKJuventus33-16519904.04.0360.05.0...33.216.050.045.859.01.01.71.00.258.5
27Pietro Terraccianoit ITAGKFiorentina33-20619904.04.0360.04.0...34.722.045.538.344.03.06.81.00.2510.2
28Stefano Turatiit ITAGKFrosinone22-02520015.05.0450.07.0...26.916.056.343.567.02.03.03.00.6013.4
\n", "

29 rows × 47 columns

\n", "
" ], "text/plain": [ " player nationality position team age \\\n", "0 Etrit Berisha al ALB GK Empoli 34-204 \n", "1 Elia Caprile it ITA GK Empoli 22-036 \n", "2 Marco Carnesecchi it ITA GK Atalanta 23-091 \n", "3 Michele Cerofolini it ITA GK Frosinone 24-269 \n", "4 Oliver Christensen dk DEN GK Fiorentina 24-192 \n", "5 Andrea Consigli it ITA GK Sassuolo 36-246 \n", "6 Alessio Cragno it ITA GK Sassuolo 29-094 \n", "7 Michele Di Gregorio it ITA GK Monza 26-065 \n", "8 Wladimiro Falcone it ITA GK Lecce 28-171 \n", "9 Mike Maignan fr FRA GK Milan 28-089 \n", "10 Josep Martinez es ESP GK Genoa 25-126 \n", "11 Alex Meret it ITA GK Napoli 26-192 \n", "12 Vanja Milinković-Savić rs SRB GK Torino 26-222 \n", "13 Lorenzo Montipò it ITA GK Hellas Verona 27-222 \n", "14 Juan Musso ar ARG GK Atalanta 29-147 \n", "15 Guillermo Ochoa mx MEX GK Salernitana 38-079 \n", "16 Rui Patrício pt POR GK Roma 35-227 \n", "17 Mattia Perin it ITA GK Juventus 30-324 \n", "18 Samuele Perisan it ITA GK Empoli 26-040 \n", "19 Ivan Provedel it ITA GK Lazio 29-197 \n", "20 Boris Radunović rs SRB GK Cagliari 27-127 \n", "21 Marco Silvestri it ITA GK Udinese 32-212 \n", "22 Łukasz Skorupski pl POL GK Bologna 32-148 \n", "23 Yann Sommer ch SUI GK Inter 34-287 \n", "24 Alessandro Sorrentino it ITA GK Monza 21-180 \n", "25 Marco Sportiello it ITA GK Milan 31-143 \n", "26 Wojciech Szczęsny pl POL GK Juventus 33-165 \n", "27 Pietro Terracciano it ITA GK Fiorentina 33-206 \n", "28 Stefano Turati it ITA GK Frosinone 22-025 \n", "\n", " birth_year gk_games gk_games_starts gk_minutes gk_goals_against ... \\\n", "0 1989 4.0 4.0 360.0 10.0 ... \n", "1 2001 1.0 1.0 90.0 1.0 ... \n", "2 2000 2.0 2.0 180.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 4.0 4.0 360.0 6.0 ... \n", "6 1994 2.0 2.0 180.0 6.0 ... \n", "7 1997 5.0 5.0 450.0 6.0 ... \n", "8 1995 6.0 6.0 540.0 5.0 ... \n", "9 1995 4.0 4.0 360.0 7.0 ... \n", "10 1998 6.0 6.0 540.0 9.0 ... \n", "11 1997 6.0 6.0 540.0 6.0 ... \n", "12 1997 6.0 6.0 540.0 7.0 ... \n", "13 1996 6.0 6.0 540.0 6.0 ... \n", "14 1994 4.0 4.0 360.0 2.0 ... \n", "15 1985 6.0 6.0 540.0 10.0 ... \n", "16 1988 6.0 6.0 540.0 11.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 6.0 6.0 540.0 8.0 ... \n", "20 1996 6.0 6.0 540.0 9.0 ... \n", "21 1991 6.0 6.0 540.0 10.0 ... \n", "22 1991 6.0 6.0 540.0 4.0 ... \n", "23 1988 6.0 6.0 540.0 3.0 ... \n", "24 2002 1.0 1.0 90.0 1.0 ... \n", "25 1992 2.0 2.0 180.0 1.0 ... \n", "26 1990 4.0 4.0 360.0 5.0 ... \n", "27 1990 4.0 4.0 360.0 4.0 ... \n", "28 2001 5.0 5.0 450.0 7.0 ... \n", "\n", " gk_passes_length_avg gk_goal_kicks gk_pct_goal_kicks_launched \\\n", "0 32.1 24.0 58.3 \n", "1 42.6 4.0 50.0 \n", "2 38.2 15.0 80.0 \n", "3 38.3 5.0 60.0 \n", "4 33.2 8.0 62.5 \n", "5 39.4 42.0 26.2 \n", "6 41.2 19.0 26.3 \n", "7 30.4 34.0 52.9 \n", "8 30.9 55.0 47.3 \n", "9 29.2 23.0 60.9 \n", "10 39.1 37.0 94.6 \n", "11 24.1 21.0 0.0 \n", "12 35.6 50.0 80.0 \n", "13 45.2 50.0 84.0 \n", "14 29.0 28.0 64.3 \n", "15 35.6 47.0 46.8 \n", "16 27.5 31.0 19.4 \n", "17 29.1 11.0 9.1 \n", "18 26.3 12.0 16.7 \n", "19 28.8 29.0 27.6 \n", "20 38.5 57.0 54.4 \n", "21 30.2 45.0 26.7 \n", "22 31.1 34.0 29.4 \n", "23 29.7 39.0 20.5 \n", "24 21.0 2.0 0.0 \n", "25 28.0 2.0 0.0 \n", "26 33.2 16.0 50.0 \n", "27 34.7 22.0 45.5 \n", "28 26.9 16.0 56.3 \n", "\n", " gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n", "0 44.0 50.0 2.0 \n", "1 50.3 10.0 2.0 \n", "2 60.7 30.0 3.0 \n", "3 45.8 18.0 0.0 \n", "4 49.4 15.0 0.0 \n", "5 28.3 73.0 4.0 \n", "6 29.4 26.0 0.0 \n", "7 47.5 73.0 2.0 \n", "8 36.3 80.0 3.0 \n", "9 47.0 52.0 12.0 \n", "10 62.1 113.0 12.0 \n", "11 20.5 53.0 1.0 \n", "12 62.9 47.0 4.0 \n", "13 61.5 72.0 1.0 \n", "14 48.9 43.0 4.0 \n", "15 39.9 88.0 4.0 \n", "16 24.2 62.0 2.0 \n", "17 18.9 26.0 2.0 \n", "18 29.6 18.0 0.0 \n", "19 32.3 63.0 3.0 \n", "20 45.1 87.0 5.0 \n", "21 32.8 69.0 1.0 \n", "22 33.6 89.0 3.0 \n", "23 27.3 59.0 5.0 \n", "24 23.0 8.0 1.0 \n", "25 28.5 28.0 2.0 \n", "26 45.8 59.0 1.0 \n", "27 38.3 44.0 3.0 \n", "28 43.5 67.0 2.0 \n", "\n", " gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n", "0 4.0 3.0 \n", "1 20.0 2.0 \n", "2 10.0 0.0 \n", "3 0.0 0.0 \n", "4 0.0 3.0 \n", "5 5.5 3.0 \n", "6 0.0 7.0 \n", "7 2.7 2.0 \n", "8 3.8 3.0 \n", "9 23.1 3.0 \n", "10 10.6 2.0 \n", "11 1.9 8.0 \n", "12 8.5 9.0 \n", "13 1.4 12.0 \n", "14 9.3 12.0 \n", "15 4.5 3.0 \n", "16 3.2 3.0 \n", "17 7.7 2.0 \n", "18 0.0 1.0 \n", "19 4.8 7.0 \n", "20 5.7 4.0 \n", "21 1.4 3.0 \n", "22 3.4 2.0 \n", "23 8.5 2.0 \n", "24 12.5 0.0 \n", "25 7.1 2.0 \n", "26 1.7 1.0 \n", "27 6.8 1.0 \n", "28 3.0 3.0 \n", "\n", " gk_def_actions_outside_pen_area_per90 gk_avg_distance_def_actions \n", "0 0.75 12.7 \n", "1 2.00 12.4 \n", "2 0.00 11.2 \n", "3 0.00 0.0 \n", "4 1.50 22.0 \n", "5 0.75 13.1 \n", "6 3.50 28.9 \n", "7 0.40 10.5 \n", "8 0.50 9.6 \n", "9 0.75 9.8 \n", "10 0.33 8.5 \n", "11 1.33 17.2 \n", "12 1.50 17.5 \n", "13 2.00 20.0 \n", "14 3.00 19.9 \n", "15 0.50 13.5 \n", "16 0.50 13.7 \n", "17 1.00 15.0 \n", "18 1.00 21.0 \n", "19 1.17 16.0 \n", "20 0.67 11.9 \n", "21 0.50 13.6 \n", "22 0.33 10.3 \n", "23 0.33 9.6 \n", "24 0.00 9.0 \n", "25 1.00 13.2 \n", "26 0.25 8.5 \n", "27 0.25 10.2 \n", "28 0.60 13.4 \n", "\n", "[29 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
0Atalanta24.050.56.066.0540.011.011.00.00.0...79.055.017.00.00.00.0362.0109.097.052.9
1Bologna23.054.76.066.0540.03.02.00.01.0...73.061.08.00.01.00.0288.073.047.060.8
2Cagliari22.038.26.066.0540.02.02.00.00.0...70.047.08.00.01.00.0349.071.092.043.6
3Empoli28.045.36.066.0540.01.01.00.00.0...76.083.012.00.02.01.0281.060.082.042.3
4Fiorentina24.057.26.066.0540.012.09.00.00.0...71.070.010.00.01.00.0315.075.096.043.9
5Frosinone24.049.26.066.0540.09.05.02.02.0...61.069.016.02.00.00.0294.080.079.050.3
6Genoa22.034.36.066.0540.08.07.00.00.0...68.057.05.00.00.00.0265.083.066.055.7
7Hellas Verona22.045.26.066.0540.04.02.00.00.0...87.078.014.00.01.00.0339.0117.0116.050.2
8Inter22.053.26.066.0540.015.012.02.02.0...68.067.09.02.00.00.0278.077.046.062.6
9Juventus22.050.36.066.0540.011.09.01.02.0...73.075.012.01.00.01.0280.067.041.062.0
10Lazio20.054.06.066.0540.07.06.01.01.0...72.064.07.01.00.00.0284.053.066.044.5
11Lecce22.046.76.066.0540.08.06.02.02.0...82.086.05.01.00.00.0286.073.067.052.1
12Milan23.056.86.066.0540.013.08.03.03.0...63.077.08.02.01.00.0287.061.065.048.4
13Monza23.054.26.066.0540.04.03.00.00.0...69.061.09.00.02.00.0257.056.074.043.1
14Napoli20.060.76.066.0540.012.07.02.04.0...65.064.016.02.01.00.0301.056.052.051.9
15Roma23.059.76.066.0540.012.09.01.01.0...70.057.09.00.01.00.0286.0104.083.055.6
16Salernitana22.052.36.066.0540.04.03.00.00.0...73.090.010.00.01.00.0298.082.0120.040.6
17Sassuolo25.042.36.066.0540.010.07.01.01.0...57.058.07.01.03.01.0265.055.085.039.3
18Torino23.049.26.066.0540.06.04.00.00.0...71.060.011.00.02.00.0301.082.093.046.9
19Udinese24.046.26.066.0540.02.02.00.00.0...79.063.06.00.02.00.0309.0101.068.059.8
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 Atalanta 24.0 50.5 6.0 66.0 540.0 \n", "1 Bologna 23.0 54.7 6.0 66.0 540.0 \n", "2 Cagliari 22.0 38.2 6.0 66.0 540.0 \n", "3 Empoli 28.0 45.3 6.0 66.0 540.0 \n", "4 Fiorentina 24.0 57.2 6.0 66.0 540.0 \n", "5 Frosinone 24.0 49.2 6.0 66.0 540.0 \n", "6 Genoa 22.0 34.3 6.0 66.0 540.0 \n", "7 Hellas Verona 22.0 45.2 6.0 66.0 540.0 \n", "8 Inter 22.0 53.2 6.0 66.0 540.0 \n", "9 Juventus 22.0 50.3 6.0 66.0 540.0 \n", "10 Lazio 20.0 54.0 6.0 66.0 540.0 \n", "11 Lecce 22.0 46.7 6.0 66.0 540.0 \n", "12 Milan 23.0 56.8 6.0 66.0 540.0 \n", "13 Monza 23.0 54.2 6.0 66.0 540.0 \n", "14 Napoli 20.0 60.7 6.0 66.0 540.0 \n", "15 Roma 23.0 59.7 6.0 66.0 540.0 \n", "16 Salernitana 22.0 52.3 6.0 66.0 540.0 \n", "17 Sassuolo 25.0 42.3 6.0 66.0 540.0 \n", "18 Torino 23.0 49.2 6.0 66.0 540.0 \n", "19 Udinese 24.0 46.2 6.0 66.0 540.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 11.0 11.0 0.0 0.0 ... 79.0 55.0 17.0 \n", "1 3.0 2.0 0.0 1.0 ... 73.0 61.0 8.0 \n", "2 2.0 2.0 0.0 0.0 ... 70.0 47.0 8.0 \n", "3 1.0 1.0 0.0 0.0 ... 76.0 83.0 12.0 \n", "4 12.0 9.0 0.0 0.0 ... 71.0 70.0 10.0 \n", "5 9.0 5.0 2.0 2.0 ... 61.0 69.0 16.0 \n", "6 8.0 7.0 0.0 0.0 ... 68.0 57.0 5.0 \n", "7 4.0 2.0 0.0 0.0 ... 87.0 78.0 14.0 \n", "8 15.0 12.0 2.0 2.0 ... 68.0 67.0 9.0 \n", "9 11.0 9.0 1.0 2.0 ... 73.0 75.0 12.0 \n", "10 7.0 6.0 1.0 1.0 ... 72.0 64.0 7.0 \n", "11 8.0 6.0 2.0 2.0 ... 82.0 86.0 5.0 \n", "12 13.0 8.0 3.0 3.0 ... 63.0 77.0 8.0 \n", "13 4.0 3.0 0.0 0.0 ... 69.0 61.0 9.0 \n", "14 12.0 7.0 2.0 4.0 ... 65.0 64.0 16.0 \n", "15 12.0 9.0 1.0 1.0 ... 70.0 57.0 9.0 \n", "16 4.0 3.0 0.0 0.0 ... 73.0 90.0 10.0 \n", "17 10.0 7.0 1.0 1.0 ... 57.0 58.0 7.0 \n", "18 6.0 4.0 0.0 0.0 ... 71.0 60.0 11.0 \n", "19 2.0 2.0 0.0 0.0 ... 79.0 63.0 6.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 362.0 109.0 \n", "1 0.0 1.0 0.0 288.0 73.0 \n", "2 0.0 1.0 0.0 349.0 71.0 \n", "3 0.0 2.0 1.0 281.0 60.0 \n", "4 0.0 1.0 0.0 315.0 75.0 \n", "5 2.0 0.0 0.0 294.0 80.0 \n", "6 0.0 0.0 0.0 265.0 83.0 \n", "7 0.0 1.0 0.0 339.0 117.0 \n", "8 2.0 0.0 0.0 278.0 77.0 \n", "9 1.0 0.0 1.0 280.0 67.0 \n", "10 1.0 0.0 0.0 284.0 53.0 \n", "11 1.0 0.0 0.0 286.0 73.0 \n", "12 2.0 1.0 0.0 287.0 61.0 \n", "13 0.0 2.0 0.0 257.0 56.0 \n", "14 2.0 1.0 0.0 301.0 56.0 \n", "15 0.0 1.0 0.0 286.0 104.0 \n", "16 0.0 1.0 0.0 298.0 82.0 \n", "17 1.0 3.0 1.0 265.0 55.0 \n", "18 0.0 2.0 0.0 301.0 82.0 \n", "19 0.0 2.0 0.0 309.0 101.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 97.0 52.9 \n", "1 47.0 60.8 \n", "2 92.0 43.6 \n", "3 82.0 42.3 \n", "4 96.0 43.9 \n", "5 79.0 50.3 \n", "6 66.0 55.7 \n", "7 116.0 50.2 \n", "8 46.0 62.6 \n", "9 41.0 62.0 \n", "10 66.0 44.5 \n", "11 67.0 52.1 \n", "12 65.0 48.4 \n", "13 74.0 43.1 \n", "14 52.0 51.9 \n", "15 83.0 55.6 \n", "16 120.0 40.6 \n", "17 85.0 39.3 \n", "18 93.0 46.9 \n", "19 68.0 59.8 \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 Atalanta24.049.56.066.0540.05.04.00.00.0...57.074.04.00.00.00.0347.097.0109.047.1
1vs Bologna23.045.36.066.0540.04.04.00.01.0...71.070.016.00.01.00.0292.047.073.039.2
2vs Cagliari22.061.86.066.0540.09.06.00.01.0...50.065.011.00.00.00.0332.092.071.056.4
3vs Empoli28.054.76.066.0540.012.08.01.02.0...84.074.010.01.00.00.0313.082.060.057.7
4vs Fiorentina24.042.86.066.0540.010.08.01.01.0...75.063.08.01.00.00.0311.096.075.056.1
5vs Frosinone24.050.86.066.0540.08.06.00.00.0...73.054.015.00.02.00.0325.079.080.049.7
6vs Genoa22.065.76.066.0540.09.08.00.00.0...67.060.012.00.00.00.0295.066.083.044.3
7vs Hellas Verona22.054.86.066.0540.06.04.01.01.0...84.084.011.01.00.00.0326.0116.0117.049.8
8vs Inter22.046.86.066.0540.03.03.00.00.0...70.064.09.00.02.00.0248.046.077.037.4
9vs Juventus22.049.76.066.0540.05.03.00.00.0...80.071.06.00.02.01.0267.041.067.038.0
10vs Lazio20.046.06.066.0540.08.05.00.00.0...69.067.010.00.01.00.0282.066.053.055.5
11vs Lecce22.053.36.066.0540.05.05.00.00.0...88.078.05.00.02.00.0295.067.073.047.9
12vs Milan23.043.26.066.0540.08.07.01.01.0...80.060.08.01.03.00.0281.065.061.051.6
13vs Monza23.045.86.066.0540.07.05.02.02.0...65.068.011.02.00.00.0281.074.056.056.9
14vs Napoli20.039.36.066.0540.06.05.01.01.0...73.060.09.01.04.00.0254.052.056.048.1
15vs Roma23.040.36.066.0540.011.09.01.01.0...58.067.04.01.01.01.0267.083.0104.044.4
16vs Salernitana22.047.76.066.0540.010.07.01.01.0...94.070.012.00.00.00.0311.0120.082.059.4
17vs Sassuolo25.057.76.066.0540.011.08.02.03.0...63.055.020.02.01.01.0299.085.055.060.7
18vs Torino23.050.86.066.0540.07.04.02.02.0...61.064.07.01.00.00.0302.093.082.053.1
19vs Udinese24.053.86.066.0540.010.06.02.02.0...65.074.011.01.00.00.0297.068.0101.040.2
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 vs Atalanta 24.0 49.5 6.0 66.0 540.0 \n", "1 vs Bologna 23.0 45.3 6.0 66.0 540.0 \n", "2 vs Cagliari 22.0 61.8 6.0 66.0 540.0 \n", "3 vs Empoli 28.0 54.7 6.0 66.0 540.0 \n", "4 vs Fiorentina 24.0 42.8 6.0 66.0 540.0 \n", "5 vs Frosinone 24.0 50.8 6.0 66.0 540.0 \n", "6 vs Genoa 22.0 65.7 6.0 66.0 540.0 \n", "7 vs Hellas Verona 22.0 54.8 6.0 66.0 540.0 \n", "8 vs Inter 22.0 46.8 6.0 66.0 540.0 \n", "9 vs Juventus 22.0 49.7 6.0 66.0 540.0 \n", "10 vs Lazio 20.0 46.0 6.0 66.0 540.0 \n", "11 vs Lecce 22.0 53.3 6.0 66.0 540.0 \n", "12 vs Milan 23.0 43.2 6.0 66.0 540.0 \n", "13 vs Monza 23.0 45.8 6.0 66.0 540.0 \n", "14 vs Napoli 20.0 39.3 6.0 66.0 540.0 \n", "15 vs Roma 23.0 40.3 6.0 66.0 540.0 \n", "16 vs Salernitana 22.0 47.7 6.0 66.0 540.0 \n", "17 vs Sassuolo 25.0 57.7 6.0 66.0 540.0 \n", "18 vs Torino 23.0 50.8 6.0 66.0 540.0 \n", "19 vs Udinese 24.0 53.8 6.0 66.0 540.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 5.0 4.0 0.0 0.0 ... 57.0 74.0 4.0 \n", "1 4.0 4.0 0.0 1.0 ... 71.0 70.0 16.0 \n", "2 9.0 6.0 0.0 1.0 ... 50.0 65.0 11.0 \n", "3 12.0 8.0 1.0 2.0 ... 84.0 74.0 10.0 \n", "4 10.0 8.0 1.0 1.0 ... 75.0 63.0 8.0 \n", "5 8.0 6.0 0.0 0.0 ... 73.0 54.0 15.0 \n", "6 9.0 8.0 0.0 0.0 ... 67.0 60.0 12.0 \n", "7 6.0 4.0 1.0 1.0 ... 84.0 84.0 11.0 \n", "8 3.0 3.0 0.0 0.0 ... 70.0 64.0 9.0 \n", "9 5.0 3.0 0.0 0.0 ... 80.0 71.0 6.0 \n", "10 8.0 5.0 0.0 0.0 ... 69.0 67.0 10.0 \n", "11 5.0 5.0 0.0 0.0 ... 88.0 78.0 5.0 \n", "12 8.0 7.0 1.0 1.0 ... 80.0 60.0 8.0 \n", "13 7.0 5.0 2.0 2.0 ... 65.0 68.0 11.0 \n", "14 6.0 5.0 1.0 1.0 ... 73.0 60.0 9.0 \n", "15 11.0 9.0 1.0 1.0 ... 58.0 67.0 4.0 \n", "16 10.0 7.0 1.0 1.0 ... 94.0 70.0 12.0 \n", "17 11.0 8.0 2.0 3.0 ... 63.0 55.0 20.0 \n", "18 7.0 4.0 2.0 2.0 ... 61.0 64.0 7.0 \n", "19 10.0 6.0 2.0 2.0 ... 65.0 74.0 11.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 347.0 97.0 \n", "1 0.0 1.0 0.0 292.0 47.0 \n", "2 0.0 0.0 0.0 332.0 92.0 \n", "3 1.0 0.0 0.0 313.0 82.0 \n", "4 1.0 0.0 0.0 311.0 96.0 \n", "5 0.0 2.0 0.0 325.0 79.0 \n", "6 0.0 0.0 0.0 295.0 66.0 \n", "7 1.0 0.0 0.0 326.0 116.0 \n", "8 0.0 2.0 0.0 248.0 46.0 \n", "9 0.0 2.0 1.0 267.0 41.0 \n", "10 0.0 1.0 0.0 282.0 66.0 \n", "11 0.0 2.0 0.0 295.0 67.0 \n", "12 1.0 3.0 0.0 281.0 65.0 \n", "13 2.0 0.0 0.0 281.0 74.0 \n", "14 1.0 4.0 0.0 254.0 52.0 \n", "15 1.0 1.0 1.0 267.0 83.0 \n", "16 0.0 0.0 0.0 311.0 120.0 \n", "17 2.0 1.0 1.0 299.0 85.0 \n", "18 1.0 0.0 0.0 302.0 93.0 \n", "19 1.0 0.0 0.0 297.0 68.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 109.0 47.1 \n", "1 73.0 39.2 \n", "2 71.0 56.4 \n", "3 60.0 57.7 \n", "4 75.0 56.1 \n", "5 80.0 49.7 \n", "6 83.0 44.3 \n", "7 117.0 49.8 \n", "8 77.0 37.4 \n", "9 67.0 38.0 \n", "10 53.0 55.5 \n", "11 73.0 47.9 \n", "12 61.0 51.6 \n", "13 56.0 56.9 \n", "14 56.0 48.1 \n", "15 104.0 44.4 \n", "16 82.0 59.4 \n", "17 55.0 60.7 \n", "18 82.0 53.1 \n", "19 101.0 40.2 \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 }