{ "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": 15, "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
0Michel Aebischerch SUIMFBologna26-24619973.03.0257.00.0...4.03.00.00.00.00.019.02.01.066.7
1Luis Albertoes ESPMFLazio30-34619923.03.0270.01.0...2.03.00.00.00.00.018.02.03.040.0
2Pontus Almqvistse SWEFWLecce24-06119993.03.0270.01.0...2.03.01.00.00.00.010.00.02.00.0
3Lorenzo Amatucciit ITAMFFiorentina19-21620041.00.016.00.0...1.00.00.00.00.00.01.00.01.00.0
4Bruno Amionear ARGMFHellas Verona21-24920021.00.02.00.0...1.00.00.00.00.00.00.00.00.00.0
..................................................................
394Joshua Zirkzeenl NEDFWBologna22-11020013.03.0266.01.0...2.00.01.00.00.00.010.06.02.075.0
395Zitoao ANGFWCagliari21-18420023.02.0207.01.0...2.06.02.00.00.00.04.01.04.020.0
396Nadir Zorteait ITADFAtalanta24-08219992.00.064.01.0...1.00.00.00.00.00.04.00.01.00.0
397Milan Đurićba BIHFW,MFHellas Verona33-11019903.01.0123.00.0...6.01.01.00.00.00.04.016.010.061.5
398Mateusz Łęgowskipl POLMF,DFSalernitana20-22320033.01.095.00.0...3.02.00.00.00.00.010.02.03.040.0
\n", "

399 rows × 115 columns

\n", "
" ], "text/plain": [ " player nationality position team age birth_year \\\n", "0 Michel Aebischer ch SUI MF Bologna 26-246 1997 \n", "1 Luis Alberto es ESP MF Lazio 30-346 1992 \n", "2 Pontus Almqvist se SWE FW Lecce 24-061 1999 \n", "3 Lorenzo Amatucci it ITA MF Fiorentina 19-216 2004 \n", "4 Bruno Amione ar ARG MF Hellas Verona 21-249 2002 \n", ".. ... ... ... ... ... ... \n", "394 Joshua Zirkzee nl NED FW Bologna 22-110 2001 \n", "395 Zito ao ANG FW Cagliari 21-184 2002 \n", "396 Nadir Zortea it ITA DF Atalanta 24-082 1999 \n", "397 Milan Đurić ba BIH FW,MF Hellas Verona 33-110 1990 \n", "398 Mateusz Łęgowski pl POL MF,DF Salernitana 20-223 2003 \n", "\n", " games games_starts minutes goals ... fouls fouled offsides \\\n", "0 3.0 3.0 257.0 0.0 ... 4.0 3.0 0.0 \n", "1 3.0 3.0 270.0 1.0 ... 2.0 3.0 0.0 \n", "2 3.0 3.0 270.0 1.0 ... 2.0 3.0 1.0 \n", "3 1.0 0.0 16.0 0.0 ... 1.0 0.0 0.0 \n", "4 1.0 0.0 2.0 0.0 ... 1.0 0.0 0.0 \n", ".. ... ... ... ... ... ... ... ... \n", "394 3.0 3.0 266.0 1.0 ... 2.0 0.0 1.0 \n", "395 3.0 2.0 207.0 1.0 ... 2.0 6.0 2.0 \n", "396 2.0 0.0 64.0 1.0 ... 1.0 0.0 0.0 \n", "397 3.0 1.0 123.0 0.0 ... 6.0 1.0 1.0 \n", "398 3.0 1.0 95.0 0.0 ... 3.0 2.0 0.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 19.0 2.0 \n", "1 0.0 0.0 0.0 18.0 2.0 \n", "2 0.0 0.0 0.0 10.0 0.0 \n", "3 0.0 0.0 0.0 1.0 0.0 \n", "4 0.0 0.0 0.0 0.0 0.0 \n", ".. ... ... ... ... ... \n", "394 0.0 0.0 0.0 10.0 6.0 \n", "395 0.0 0.0 0.0 4.0 1.0 \n", "396 0.0 0.0 0.0 4.0 0.0 \n", "397 0.0 0.0 0.0 4.0 16.0 \n", "398 0.0 0.0 0.0 10.0 2.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 1.0 66.7 \n", "1 3.0 40.0 \n", "2 2.0 0.0 \n", "3 1.0 0.0 \n", "4 0.0 0.0 \n", ".. ... ... \n", "394 2.0 75.0 \n", "395 4.0 20.0 \n", "396 1.0 0.0 \n", "397 10.0 61.5 \n", "398 3.0 40.0 \n", "\n", "[399 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", "
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-18319891.01.090.02.0...29.77.028.628.017.00.00.02.02.0016.6
1Elia Caprileit ITAGKEmpoli22-01520011.01.090.01.0...42.64.050.050.310.02.020.02.02.0012.4
2Michele Cerofoliniit ITAGKFrosinone24-24819991.01.090.01.0...38.35.060.045.818.00.00.00.00.000.0
3Oliver Christensendk DENGKFiorentina24-17119992.02.0180.06.0...33.28.062.549.415.00.00.03.01.5022.0
4Andrea Consigliit ITAGKSassuolo36-22519873.03.0270.05.0...37.134.026.528.146.02.04.33.01.0014.5
5Michele Di Gregorioit ITAGKMonza26-04419973.03.0270.05.0...28.722.040.940.345.02.04.42.00.6711.7
6Wladimiro Falconeit ITAGKLecce28-15019953.03.0270.03.0...35.024.062.542.332.02.06.31.00.339.0
7Mike Maignanfr FRAGKMilan28-06819953.03.0270.02.0...30.520.065.049.343.012.027.93.01.0010.3
8Josep Martinezes ESPGKGenoa25-10519983.03.0270.05.0...40.114.092.962.264.08.012.52.00.679.7
9Alex Meretit ITAGKNapoli26-17119973.03.0270.03.0...24.48.00.021.415.01.06.75.01.6718.1
10Vanja Milinković-Savićrs SRBGKTorino26-20119973.03.0270.04.0...34.129.069.058.923.00.00.01.00.3314.2
11Lorenzo Montipòit ITAGKHellas Verona27-20119963.03.0270.04.0...43.028.085.761.044.01.02.38.02.6720.9
12Juan Mussoar ARGGKAtalanta29-12619943.03.0270.02.0...29.318.055.646.128.02.07.18.02.6722.0
13Guillermo Ochoamx MEXGKSalernitana38-05819853.03.0270.05.0...38.731.061.346.351.03.05.91.00.338.3
14Rui Patríciopt PORGKRoma35-20619883.03.0270.06.0...29.712.016.724.515.00.00.02.00.6716.2
15Mattia Perinit ITAGKJuventus30-30319922.02.0180.01.0...29.111.09.118.926.02.07.72.01.0015.0
16Samuele Perisanit ITAGKEmpoli26-01919971.01.090.02.0...26.312.016.729.618.00.00.01.01.0021.0
17Ivan Provedelit ITAGKLazio29-17619943.03.0270.04.0...26.111.027.331.639.02.05.16.02.0016.3
18Boris Radunovićrs SRBGKCagliari27-10619963.03.0270.04.0...39.428.071.452.849.02.04.12.00.6711.9
19Marco Silvestriit ITAGKUdinese32-19119913.03.0270.04.0...31.421.038.139.533.00.00.02.00.6713.4
20Łukasz Skorupskipl POLGKBologna32-12719913.03.0270.04.0...33.019.036.837.045.02.04.42.00.6711.3
21Yann Sommerch SUIGKInter34-26619883.03.0270.00.0...31.421.023.831.035.01.02.90.00.006.8
22Wojciech Szczęsnypl POLGKJuventus33-14419901.01.090.00.0...31.63.066.753.316.01.06.30.00.0010.8
23Pietro Terraccianoit ITAGKFiorentina33-18519901.01.090.01.0...30.04.00.023.311.00.00.00.00.0013.3
24Stefano Turatiit ITAGKFrosinone22-00420012.02.0180.03.0...27.110.050.040.725.02.08.02.01.0011.8
\n", "

25 rows × 47 columns

\n", "
" ], "text/plain": [ " player nationality position team age \\\n", "0 Etrit Berisha al ALB GK Empoli 34-183 \n", "1 Elia Caprile it ITA GK Empoli 22-015 \n", "2 Michele Cerofolini it ITA GK Frosinone 24-248 \n", "3 Oliver Christensen dk DEN GK Fiorentina 24-171 \n", "4 Andrea Consigli it ITA GK Sassuolo 36-225 \n", "5 Michele Di Gregorio it ITA GK Monza 26-044 \n", "6 Wladimiro Falcone it ITA GK Lecce 28-150 \n", "7 Mike Maignan fr FRA GK Milan 28-068 \n", "8 Josep Martinez es ESP GK Genoa 25-105 \n", "9 Alex Meret it ITA GK Napoli 26-171 \n", "10 Vanja Milinković-Savić rs SRB GK Torino 26-201 \n", "11 Lorenzo Montipò it ITA GK Hellas Verona 27-201 \n", "12 Juan Musso ar ARG GK Atalanta 29-126 \n", "13 Guillermo Ochoa mx MEX GK Salernitana 38-058 \n", "14 Rui Patrício pt POR GK Roma 35-206 \n", "15 Mattia Perin it ITA GK Juventus 30-303 \n", "16 Samuele Perisan it ITA GK Empoli 26-019 \n", "17 Ivan Provedel it ITA GK Lazio 29-176 \n", "18 Boris Radunović rs SRB GK Cagliari 27-106 \n", "19 Marco Silvestri it ITA GK Udinese 32-191 \n", "20 Łukasz Skorupski pl POL GK Bologna 32-127 \n", "21 Yann Sommer ch SUI GK Inter 34-266 \n", "22 Wojciech Szczęsny pl POL GK Juventus 33-144 \n", "23 Pietro Terracciano it ITA GK Fiorentina 33-185 \n", "24 Stefano Turati it ITA GK Frosinone 22-004 \n", "\n", " birth_year gk_games gk_games_starts gk_minutes gk_goals_against ... \\\n", "0 1989 1.0 1.0 90.0 2.0 ... \n", "1 2001 1.0 1.0 90.0 1.0 ... \n", "2 1999 1.0 1.0 90.0 1.0 ... \n", "3 1999 2.0 2.0 180.0 6.0 ... \n", "4 1987 3.0 3.0 270.0 5.0 ... \n", "5 1997 3.0 3.0 270.0 5.0 ... \n", "6 1995 3.0 3.0 270.0 3.0 ... \n", "7 1995 3.0 3.0 270.0 2.0 ... \n", "8 1998 3.0 3.0 270.0 5.0 ... \n", "9 1997 3.0 3.0 270.0 3.0 ... \n", "10 1997 3.0 3.0 270.0 4.0 ... \n", "11 1996 3.0 3.0 270.0 4.0 ... \n", "12 1994 3.0 3.0 270.0 2.0 ... \n", "13 1985 3.0 3.0 270.0 5.0 ... \n", "14 1988 3.0 3.0 270.0 6.0 ... \n", "15 1992 2.0 2.0 180.0 1.0 ... \n", "16 1997 1.0 1.0 90.0 2.0 ... \n", "17 1994 3.0 3.0 270.0 4.0 ... \n", "18 1996 3.0 3.0 270.0 4.0 ... \n", "19 1991 3.0 3.0 270.0 4.0 ... \n", "20 1991 3.0 3.0 270.0 4.0 ... \n", "21 1988 3.0 3.0 270.0 0.0 ... \n", "22 1990 1.0 1.0 90.0 0.0 ... \n", "23 1990 1.0 1.0 90.0 1.0 ... \n", "24 2001 2.0 2.0 180.0 3.0 ... \n", "\n", " gk_passes_length_avg gk_goal_kicks gk_pct_goal_kicks_launched \\\n", "0 29.7 7.0 28.6 \n", "1 42.6 4.0 50.0 \n", "2 38.3 5.0 60.0 \n", "3 33.2 8.0 62.5 \n", "4 37.1 34.0 26.5 \n", "5 28.7 22.0 40.9 \n", "6 35.0 24.0 62.5 \n", "7 30.5 20.0 65.0 \n", "8 40.1 14.0 92.9 \n", "9 24.4 8.0 0.0 \n", "10 34.1 29.0 69.0 \n", "11 43.0 28.0 85.7 \n", "12 29.3 18.0 55.6 \n", "13 38.7 31.0 61.3 \n", "14 29.7 12.0 16.7 \n", "15 29.1 11.0 9.1 \n", "16 26.3 12.0 16.7 \n", "17 26.1 11.0 27.3 \n", "18 39.4 28.0 71.4 \n", "19 31.4 21.0 38.1 \n", "20 33.0 19.0 36.8 \n", "21 31.4 21.0 23.8 \n", "22 31.6 3.0 66.7 \n", "23 30.0 4.0 0.0 \n", "24 27.1 10.0 50.0 \n", "\n", " gk_goal_kick_length_avg gk_crosses gk_crosses_stopped \\\n", "0 28.0 17.0 0.0 \n", "1 50.3 10.0 2.0 \n", "2 45.8 18.0 0.0 \n", "3 49.4 15.0 0.0 \n", "4 28.1 46.0 2.0 \n", "5 40.3 45.0 2.0 \n", "6 42.3 32.0 2.0 \n", "7 49.3 43.0 12.0 \n", "8 62.2 64.0 8.0 \n", "9 21.4 15.0 1.0 \n", "10 58.9 23.0 0.0 \n", "11 61.0 44.0 1.0 \n", "12 46.1 28.0 2.0 \n", "13 46.3 51.0 3.0 \n", "14 24.5 15.0 0.0 \n", "15 18.9 26.0 2.0 \n", "16 29.6 18.0 0.0 \n", "17 31.6 39.0 2.0 \n", "18 52.8 49.0 2.0 \n", "19 39.5 33.0 0.0 \n", "20 37.0 45.0 2.0 \n", "21 31.0 35.0 1.0 \n", "22 53.3 16.0 1.0 \n", "23 23.3 11.0 0.0 \n", "24 40.7 25.0 2.0 \n", "\n", " gk_crosses_stopped_pct gk_def_actions_outside_pen_area \\\n", "0 0.0 2.0 \n", "1 20.0 2.0 \n", "2 0.0 0.0 \n", "3 0.0 3.0 \n", "4 4.3 3.0 \n", "5 4.4 2.0 \n", "6 6.3 1.0 \n", "7 27.9 3.0 \n", "8 12.5 2.0 \n", "9 6.7 5.0 \n", "10 0.0 1.0 \n", "11 2.3 8.0 \n", "12 7.1 8.0 \n", "13 5.9 1.0 \n", "14 0.0 2.0 \n", "15 7.7 2.0 \n", "16 0.0 1.0 \n", "17 5.1 6.0 \n", "18 4.1 2.0 \n", "19 0.0 2.0 \n", "20 4.4 2.0 \n", "21 2.9 0.0 \n", "22 6.3 0.0 \n", "23 0.0 0.0 \n", "24 8.0 2.0 \n", "\n", " gk_def_actions_outside_pen_area_per90 gk_avg_distance_def_actions \n", "0 2.00 16.6 \n", "1 2.00 12.4 \n", "2 0.00 0.0 \n", "3 1.50 22.0 \n", "4 1.00 14.5 \n", "5 0.67 11.7 \n", "6 0.33 9.0 \n", "7 1.00 10.3 \n", "8 0.67 9.7 \n", "9 1.67 18.1 \n", "10 0.33 14.2 \n", "11 2.67 20.9 \n", "12 2.67 22.0 \n", "13 0.33 8.3 \n", "14 0.67 16.2 \n", "15 1.00 15.0 \n", "16 1.00 21.0 \n", "17 2.00 16.3 \n", "18 0.67 11.9 \n", "19 0.67 13.4 \n", "20 0.67 11.3 \n", "21 0.00 6.8 \n", "22 0.00 10.8 \n", "23 0.00 13.3 \n", "24 1.00 11.8 \n", "\n", "[25 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
0Atalanta20.051.73.033.0270.06.06.00.00.0...34.027.07.00.00.00.0172.042.044.048.8
1Bologna20.055.33.033.0270.03.02.00.01.0...32.025.03.00.00.00.0153.029.023.055.8
2Cagliari19.035.03.033.0270.01.01.00.00.0...34.025.04.00.01.00.0190.037.044.045.7
3Empoli26.048.03.033.0270.00.00.00.00.0...38.044.05.00.01.00.0131.030.042.041.7
4Fiorentina21.062.33.033.0270.06.05.00.00.0...41.038.04.00.01.00.0141.032.038.045.7
5Frosinone21.046.03.033.0270.03.02.01.01.0...33.040.06.01.00.00.0154.042.046.047.7
6Genoa18.033.03.033.0270.02.01.00.00.0...37.029.04.00.00.00.0128.044.032.057.9
7Hellas Verona19.044.73.033.0270.04.02.00.00.0...48.036.07.00.01.00.0157.071.054.056.8
8Inter18.051.33.033.0270.08.07.01.01.0...31.033.03.01.00.00.0156.036.024.060.0
9Juventus21.053.03.033.0270.06.04.01.02.0...38.035.09.01.00.00.0140.026.022.054.2
10Lazio19.053.33.033.0270.03.03.00.00.0...34.033.04.00.00.00.0149.026.039.040.0
11Lecce18.045.03.033.0270.06.05.01.01.0...44.045.03.00.00.00.0148.046.033.058.2
12Milan18.054.03.033.0270.08.05.03.03.0...32.039.04.02.00.00.0134.027.034.044.3
13Monza21.055.33.033.0270.02.02.00.00.0...36.025.04.00.00.00.0122.027.037.042.2
14Napoli18.060.33.033.0270.06.03.01.02.0...34.027.011.01.01.00.0156.033.019.063.5
15Roma21.058.33.033.0270.04.03.00.00.0...38.041.05.00.01.00.0145.064.045.058.7
16Salernitana21.050.03.033.0270.03.03.00.00.0...36.047.03.00.01.00.0127.037.068.035.2
17Sassuolo22.043.03.033.0270.03.02.01.01.0...27.033.01.01.02.00.0127.030.040.042.9
18Torino20.053.73.033.0270.02.02.00.00.0...37.031.08.00.02.00.0141.041.046.047.1
19Udinese18.046.73.033.0270.01.01.00.00.0...45.030.04.00.01.00.0148.048.038.055.8
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 Atalanta 20.0 51.7 3.0 33.0 270.0 \n", "1 Bologna 20.0 55.3 3.0 33.0 270.0 \n", "2 Cagliari 19.0 35.0 3.0 33.0 270.0 \n", "3 Empoli 26.0 48.0 3.0 33.0 270.0 \n", "4 Fiorentina 21.0 62.3 3.0 33.0 270.0 \n", "5 Frosinone 21.0 46.0 3.0 33.0 270.0 \n", "6 Genoa 18.0 33.0 3.0 33.0 270.0 \n", "7 Hellas Verona 19.0 44.7 3.0 33.0 270.0 \n", "8 Inter 18.0 51.3 3.0 33.0 270.0 \n", "9 Juventus 21.0 53.0 3.0 33.0 270.0 \n", "10 Lazio 19.0 53.3 3.0 33.0 270.0 \n", "11 Lecce 18.0 45.0 3.0 33.0 270.0 \n", "12 Milan 18.0 54.0 3.0 33.0 270.0 \n", "13 Monza 21.0 55.3 3.0 33.0 270.0 \n", "14 Napoli 18.0 60.3 3.0 33.0 270.0 \n", "15 Roma 21.0 58.3 3.0 33.0 270.0 \n", "16 Salernitana 21.0 50.0 3.0 33.0 270.0 \n", "17 Sassuolo 22.0 43.0 3.0 33.0 270.0 \n", "18 Torino 20.0 53.7 3.0 33.0 270.0 \n", "19 Udinese 18.0 46.7 3.0 33.0 270.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 6.0 6.0 0.0 0.0 ... 34.0 27.0 7.0 \n", "1 3.0 2.0 0.0 1.0 ... 32.0 25.0 3.0 \n", "2 1.0 1.0 0.0 0.0 ... 34.0 25.0 4.0 \n", "3 0.0 0.0 0.0 0.0 ... 38.0 44.0 5.0 \n", "4 6.0 5.0 0.0 0.0 ... 41.0 38.0 4.0 \n", "5 3.0 2.0 1.0 1.0 ... 33.0 40.0 6.0 \n", "6 2.0 1.0 0.0 0.0 ... 37.0 29.0 4.0 \n", "7 4.0 2.0 0.0 0.0 ... 48.0 36.0 7.0 \n", "8 8.0 7.0 1.0 1.0 ... 31.0 33.0 3.0 \n", "9 6.0 4.0 1.0 2.0 ... 38.0 35.0 9.0 \n", "10 3.0 3.0 0.0 0.0 ... 34.0 33.0 4.0 \n", "11 6.0 5.0 1.0 1.0 ... 44.0 45.0 3.0 \n", "12 8.0 5.0 3.0 3.0 ... 32.0 39.0 4.0 \n", "13 2.0 2.0 0.0 0.0 ... 36.0 25.0 4.0 \n", "14 6.0 3.0 1.0 2.0 ... 34.0 27.0 11.0 \n", "15 4.0 3.0 0.0 0.0 ... 38.0 41.0 5.0 \n", "16 3.0 3.0 0.0 0.0 ... 36.0 47.0 3.0 \n", "17 3.0 2.0 1.0 1.0 ... 27.0 33.0 1.0 \n", "18 2.0 2.0 0.0 0.0 ... 37.0 31.0 8.0 \n", "19 1.0 1.0 0.0 0.0 ... 45.0 30.0 4.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 172.0 42.0 \n", "1 0.0 0.0 0.0 153.0 29.0 \n", "2 0.0 1.0 0.0 190.0 37.0 \n", "3 0.0 1.0 0.0 131.0 30.0 \n", "4 0.0 1.0 0.0 141.0 32.0 \n", "5 1.0 0.0 0.0 154.0 42.0 \n", "6 0.0 0.0 0.0 128.0 44.0 \n", "7 0.0 1.0 0.0 157.0 71.0 \n", "8 1.0 0.0 0.0 156.0 36.0 \n", "9 1.0 0.0 0.0 140.0 26.0 \n", "10 0.0 0.0 0.0 149.0 26.0 \n", "11 0.0 0.0 0.0 148.0 46.0 \n", "12 2.0 0.0 0.0 134.0 27.0 \n", "13 0.0 0.0 0.0 122.0 27.0 \n", "14 1.0 1.0 0.0 156.0 33.0 \n", "15 0.0 1.0 0.0 145.0 64.0 \n", "16 0.0 1.0 0.0 127.0 37.0 \n", "17 1.0 2.0 0.0 127.0 30.0 \n", "18 0.0 2.0 0.0 141.0 41.0 \n", "19 0.0 1.0 0.0 148.0 48.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 44.0 48.8 \n", "1 23.0 55.8 \n", "2 44.0 45.7 \n", "3 42.0 41.7 \n", "4 38.0 45.7 \n", "5 46.0 47.7 \n", "6 32.0 57.9 \n", "7 54.0 56.8 \n", "8 24.0 60.0 \n", "9 22.0 54.2 \n", "10 39.0 40.0 \n", "11 33.0 58.2 \n", "12 34.0 44.3 \n", "13 37.0 42.2 \n", "14 19.0 63.5 \n", "15 45.0 58.7 \n", "16 68.0 35.2 \n", "17 40.0 42.9 \n", "18 46.0 47.1 \n", "19 38.0 55.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 Atalanta20.048.33.033.0270.02.02.00.00.0...28.033.02.00.00.00.0157.044.042.051.2
1vs Bologna20.044.73.033.0270.04.04.00.00.0...32.030.07.00.01.00.0157.023.029.044.2
2vs Cagliari19.065.03.033.0270.04.03.00.01.0...27.029.04.00.00.00.0165.044.037.054.3
3vs Empoli26.052.03.033.0270.05.03.00.01.0...45.038.06.01.00.00.0152.042.030.058.3
4vs Fiorentina21.037.73.033.0270.07.06.01.01.0...42.036.03.01.00.00.0142.038.032.054.3
5vs Frosinone21.054.03.033.0270.04.03.00.00.0...41.031.04.00.01.00.0168.046.042.052.3
6vs Genoa18.067.03.033.0270.05.04.00.00.0...35.031.06.00.00.00.0148.032.044.042.1
7vs Hellas Verona19.055.33.033.0270.04.02.01.01.0...37.047.06.01.00.00.0138.054.071.043.2
8vs Inter18.048.73.033.0270.00.00.00.00.0...34.030.03.00.01.00.0128.024.036.040.0
9vs Juventus21.047.03.033.0270.01.01.00.00.0...39.036.05.00.02.00.0134.022.026.045.8
10vs Lazio19.046.73.033.0270.04.02.00.00.0...36.031.06.00.00.00.0155.039.026.060.0
11vs Lecce18.055.03.033.0270.03.03.00.00.0...47.043.04.00.01.00.0150.033.046.041.8
12vs Milan18.046.03.033.0270.02.02.00.00.0...40.031.05.00.03.00.0145.034.027.055.7
13vs Monza21.044.73.033.0270.05.05.00.00.0...26.035.06.00.00.00.0144.037.027.057.8
14vs Napoli18.039.73.033.0270.03.02.01.01.0...33.033.06.01.02.00.0124.019.033.036.5
15vs Roma21.041.73.033.0270.06.04.01.01.0...41.036.02.01.00.00.0114.045.064.041.3
16vs Salernitana21.050.03.033.0270.05.04.01.01.0...48.034.02.00.00.00.0151.068.037.064.8
17vs Sassuolo22.057.03.033.0270.05.04.01.02.0...35.025.010.01.01.00.0159.040.030.057.1
18vs Torino20.046.33.033.0270.04.02.02.02.0...32.033.05.01.00.00.0151.046.041.052.9
19vs Udinese18.053.33.033.0270.04.03.01.01.0...31.041.07.00.00.00.0137.038.048.044.2
\n", "

20 rows × 152 columns

\n", "
" ], "text/plain": [ " team players_used possession games games_starts minutes \\\n", "0 vs Atalanta 20.0 48.3 3.0 33.0 270.0 \n", "1 vs Bologna 20.0 44.7 3.0 33.0 270.0 \n", "2 vs Cagliari 19.0 65.0 3.0 33.0 270.0 \n", "3 vs Empoli 26.0 52.0 3.0 33.0 270.0 \n", "4 vs Fiorentina 21.0 37.7 3.0 33.0 270.0 \n", "5 vs Frosinone 21.0 54.0 3.0 33.0 270.0 \n", "6 vs Genoa 18.0 67.0 3.0 33.0 270.0 \n", "7 vs Hellas Verona 19.0 55.3 3.0 33.0 270.0 \n", "8 vs Inter 18.0 48.7 3.0 33.0 270.0 \n", "9 vs Juventus 21.0 47.0 3.0 33.0 270.0 \n", "10 vs Lazio 19.0 46.7 3.0 33.0 270.0 \n", "11 vs Lecce 18.0 55.0 3.0 33.0 270.0 \n", "12 vs Milan 18.0 46.0 3.0 33.0 270.0 \n", "13 vs Monza 21.0 44.7 3.0 33.0 270.0 \n", "14 vs Napoli 18.0 39.7 3.0 33.0 270.0 \n", "15 vs Roma 21.0 41.7 3.0 33.0 270.0 \n", "16 vs Salernitana 21.0 50.0 3.0 33.0 270.0 \n", "17 vs Sassuolo 22.0 57.0 3.0 33.0 270.0 \n", "18 vs Torino 20.0 46.3 3.0 33.0 270.0 \n", "19 vs Udinese 18.0 53.3 3.0 33.0 270.0 \n", "\n", " goals assists pens_made pens_att ... fouls fouled offsides \\\n", "0 2.0 2.0 0.0 0.0 ... 28.0 33.0 2.0 \n", "1 4.0 4.0 0.0 0.0 ... 32.0 30.0 7.0 \n", "2 4.0 3.0 0.0 1.0 ... 27.0 29.0 4.0 \n", "3 5.0 3.0 0.0 1.0 ... 45.0 38.0 6.0 \n", "4 7.0 6.0 1.0 1.0 ... 42.0 36.0 3.0 \n", "5 4.0 3.0 0.0 0.0 ... 41.0 31.0 4.0 \n", "6 5.0 4.0 0.0 0.0 ... 35.0 31.0 6.0 \n", "7 4.0 2.0 1.0 1.0 ... 37.0 47.0 6.0 \n", "8 0.0 0.0 0.0 0.0 ... 34.0 30.0 3.0 \n", "9 1.0 1.0 0.0 0.0 ... 39.0 36.0 5.0 \n", "10 4.0 2.0 0.0 0.0 ... 36.0 31.0 6.0 \n", "11 3.0 3.0 0.0 0.0 ... 47.0 43.0 4.0 \n", "12 2.0 2.0 0.0 0.0 ... 40.0 31.0 5.0 \n", "13 5.0 5.0 0.0 0.0 ... 26.0 35.0 6.0 \n", "14 3.0 2.0 1.0 1.0 ... 33.0 33.0 6.0 \n", "15 6.0 4.0 1.0 1.0 ... 41.0 36.0 2.0 \n", "16 5.0 4.0 1.0 1.0 ... 48.0 34.0 2.0 \n", "17 5.0 4.0 1.0 2.0 ... 35.0 25.0 10.0 \n", "18 4.0 2.0 2.0 2.0 ... 32.0 33.0 5.0 \n", "19 4.0 3.0 1.0 1.0 ... 31.0 41.0 7.0 \n", "\n", " pens_won pens_conceded own_goals ball_recoveries aerials_won \\\n", "0 0.0 0.0 0.0 157.0 44.0 \n", "1 0.0 1.0 0.0 157.0 23.0 \n", "2 0.0 0.0 0.0 165.0 44.0 \n", "3 1.0 0.0 0.0 152.0 42.0 \n", "4 1.0 0.0 0.0 142.0 38.0 \n", "5 0.0 1.0 0.0 168.0 46.0 \n", "6 0.0 0.0 0.0 148.0 32.0 \n", "7 1.0 0.0 0.0 138.0 54.0 \n", "8 0.0 1.0 0.0 128.0 24.0 \n", "9 0.0 2.0 0.0 134.0 22.0 \n", "10 0.0 0.0 0.0 155.0 39.0 \n", "11 0.0 1.0 0.0 150.0 33.0 \n", "12 0.0 3.0 0.0 145.0 34.0 \n", "13 0.0 0.0 0.0 144.0 37.0 \n", "14 1.0 2.0 0.0 124.0 19.0 \n", "15 1.0 0.0 0.0 114.0 45.0 \n", "16 0.0 0.0 0.0 151.0 68.0 \n", "17 1.0 1.0 0.0 159.0 40.0 \n", "18 1.0 0.0 0.0 151.0 46.0 \n", "19 0.0 0.0 0.0 137.0 38.0 \n", "\n", " aerials_lost aerials_won_pct \n", "0 42.0 51.2 \n", "1 29.0 44.2 \n", "2 37.0 54.3 \n", "3 30.0 58.3 \n", "4 32.0 54.3 \n", "5 42.0 52.3 \n", "6 44.0 42.1 \n", "7 71.0 43.2 \n", "8 36.0 40.0 \n", "9 26.0 45.8 \n", "10 26.0 60.0 \n", "11 46.0 41.8 \n", "12 27.0 55.7 \n", "13 27.0 57.8 \n", "14 33.0 36.5 \n", "15 64.0 41.3 \n", "16 37.0 64.8 \n", "17 30.0 57.1 \n", "18 41.0 52.9 \n", "19 48.0 44.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 }