[3]:
import soccerdata as sd

FBref#

[4]:
fbref = sd.FBref(leagues="ENG-Premier League", seasons=2021)
print(fbref.__doc__)
/cw/dtaijupiter/NoCsBack/dtai/pieterr/Projects/soccerdata/soccerdata/_common.py:466: UserWarning: Season id "2021" is ambiguous: interpreting as "20-21"
  warnings.warn(msg)
Provides pd.DataFrames from data at http://fbref.com.

    Data will be downloaded as necessary and cached locally in
    ``~/soccerdata/data/FBref``.

    Parameters
    ----------
    leagues : string or iterable, optional
        IDs of leagues to include.
    seasons : string, int or list, optional
        Seasons to include. Supports multiple formats.
        Examples: '16-17'; 2016; '2016-17'; [14, 15, 16]
    proxy : 'tor' or or dict or list(dict) or callable, optional
        Use a proxy to hide your IP address. Valid options are:
            - "tor": Uses the Tor network. Tor should be running in
              the background on port 9050.
            - dict: A dictionary with the proxy to use. The dict should be
              a mapping of supported protocols to proxy addresses. For example::

                  {
                      'http': 'http://10.10.1.10:3128',
                      'https': 'http://10.10.1.10:1080',
                  }

            - list(dict): A list of proxies to choose from. A different proxy will
              be selected from this list after failed requests, allowing rotating
              proxies.
            - callable: A function that returns a valid proxy. This function will
              be called after failed requests, allowing rotating proxies.
    no_cache : bool
        If True, will not use cached data.
    no_store : bool
        If True, will not store downloaded data.
    data_dir : Path
        Path to directory where data will be cached.

Team season stats#

[5]:
team_season_stats = fbref.read_team_season_stats(stat_type="standard")
team_season_stats.head()
[5]:
# Pl Age Poss Playing Time Performance Per 90 Minutes Expected Per 90 Minutes url
MP Starts Min 90s Gls Ast G-PK PK PKatt CrdY CrdR Gls Ast G+A G-PK G+A-PK xG npxG xA npxG+xA xG xA xG+xA npxG npxG+xA
league season team
ENG-Premier League 2021 Arsenal 29 25.9 53.8 38 418 3420 38.0 53 38 47 6 6 49 5 1.39 1.00 2.39 1.24 2.24 53.5 49.0 36.6 85.5 1.41 0.96 2.37 1.29 2.25 /en/squads/18bb7c10/2020-2021/Arsenal-Stats
Aston Villa 24 25.2 48.1 38 418 3420 38.0 52 38 47 5 6 71 4 1.37 1.00 2.37 1.24 2.24 52.9 48.5 37.1 85.6 1.39 0.98 2.37 1.28 2.25 /en/squads/8602292d/2020-2021/Aston-Villa-Stats
Brighton 27 25.8 51.3 38 418 3420 38.0 39 24 33 6 9 49 6 1.03 0.63 1.66 0.87 1.50 51.6 44.8 33.0 77.8 1.36 0.87 2.23 1.18 2.05 /en/squads/d07537b9/2020-2021/Brighton-and-Hov...
Burnley 25 28.3 41.7 38 418 3420 38.0 32 20 29 3 3 48 0 0.84 0.53 1.37 0.76 1.29 39.9 37.6 27.1 64.8 1.05 0.71 1.76 0.99 1.70 /en/squads/943e8050/2020-2021/Burnley-Stats
Chelsea 27 26.0 61.4 38 418 3420 38.0 56 38 48 8 10 51 3 1.47 1.00 2.47 1.26 2.26 64.0 56.4 42.4 98.8 1.68 1.12 2.80 1.48 2.60 /en/squads/cff3d9bb/2020-2021/Chelsea-Stats

Player season stats#

[6]:
player_season_stats = fbref.read_player_season_stats(stat_type="standard")
player_season_stats.head()
[6]:
Expected Per 90 Minutes Performance Playing Time Nation Pos Age
npxG npxG+xA xA xG Ast G+A G+A-PK G-PK Gls npxG npxG+xA xA xG xG+xA Ast CrdR CrdY G-PK Gls PK PKatt 90s MP Min Starts
league season team player
ENG-Premier League 2021 Arsenal Aaron Ramsdale 0.0 0.0 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.0 0.0 1.0 0.0 0.0 0.0 0.0 28.0 28 2520.0 28 ENG GK 23-344
Ainsley Maitland-Niles 0.0 0.4 0.3 0.0 0.00 0.00 0.00 0.00 0.00 0.01 0.13 0.12 0.01 0.13 0.0 0.0 0.0 0.0 0.0 0.0 0.0 3.0 8 268.0 2 ENG MF 24-237
Albert Sambi Lokonga 0.5 1.3 0.7 0.5 0.00 0.00 0.00 0.00 0.00 0.04 0.10 0.06 0.04 0.10 0.0 0.0 5.0 0.0 0.0 0.0 0.0 12.3 17 1105.0 12 BEL MF 22-183
Alexandre Lacazette 5.6 7.5 1.9 7.8 0.37 0.58 0.47 0.11 0.21 0.29 0.40 0.10 0.41 0.52 7.0 0.0 0.0 2.0 4.0 2.0 3.0 19.0 26 1710.0 20 FRA FW,MF 30-330
Arthur Okonkwo NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0 NaN 0 ENG GK 20-226

Game schedule#

[7]:
epl_schedule = fbref.read_schedule()
epl_schedule.head()
[7]:
week day date time home_team home_xg score away_xg away_team attendance venue referee match_report notes game_id
league season game
ENG-Premier League 2021 2020-09-12 Crystal Palace-Southampton 1.0 Sat 2020-09-12 15:00 Crystal Palace 0.7 1–0 0.8 Southampton NaN Selhurst Park Jonathan Moss /en/matches/db261cb0/Crystal-Palace-Southampto... NaN db261cb0
2020-09-12 Fulham-Arsenal 1.0 Sat 2020-09-12 12:30 Fulham 0.2 0–3 1.8 Arsenal NaN Craven Cottage Chris Kavanagh /en/matches/bf52349b/Fulham-Arsenal-September-... NaN bf52349b
2020-09-12 Liverpool-Leeds United 1.0 Sat 2020-09-12 17:30 Liverpool 3.3 4–3 0.6 Leeds United NaN Anfield Michael Oliver /en/matches/21b58926/Liverpool-Leeds-United-Se... NaN 21b58926
2020-09-12 West Ham-Newcastle Utd 1.0 Sat 2020-09-12 20:00 West Ham 1.1 0–2 1.5 Newcastle Utd NaN London Stadium Stuart Attwell /en/matches/78495ced/West-Ham-United-Newcastle... NaN 78495ced
2020-09-13 Tottenham-Everton 1.0 Sun 2020-09-13 16:30 Tottenham 1.0 0–1 1.4 Everton NaN Tottenham Hotspur Stadium Martin Atkinson /en/matches/fc7f9aa1/Tottenham-Hotspur-Everton... NaN fc7f9aa1

Line ups#

[8]:
lineups = fbref.read_lineup(match_id='db261cb0')
lineups.head()
[8]:
jersey_number is_starter
league season game team player
ENG-Premier League 2021 2020-09-12 Crystal Palace-Southampton Crystal Palace Vicente Guaita 31 True
Joel Ward 2 True
Scott Dann 6 True
Cheikhou Kouyaté 8 True
Jordan Ayew 9 True

Player match stats#

[9]:
player_match_stats = fbref.read_player_match_stats(stat_type="passing", match_id='db261cb0')
player_match_stats.head()
[9]:
Long Medium Short Total # Ast xA KP 1/3 PPA CrsPA Prog Nation Pos Age Min game_id
Att Cmp Cmp% Att Cmp Cmp% Att Cmp Cmp% Att Cmp Cmp% PrgDist TotDist
league season game team player
ENG-Premier League 2021 2020-09-12 Crystal Palace-Southampton Southampton Alex McCarthy 23 11 47.8 15 15 100.0 13 13 100.0 51 39 76.5 623 961 1.0 0 0.0 0 1 1 0 0 eng ENG GK 30-284 90 NaN
Che Adams 1 0 0.0 4 4 100.0 12 9 75.0 18 14 77.8 45 177 10.0 0 0.1 1 1 1 0 2 sct SCO FW 24-061 84 NaN
Danny Ings 1 0 0.0 4 2 50.0 8 7 87.5 18 11 61.1 61 115 9.0 0 0.1 1 1 2 1 2 eng ENG FW 28-051 90 NaN
Jack Stephens 21 11 52.4 42 38 90.5 21 17 81.0 86 66 76.7 673 1532 5.0 0 0.0 0 5 2 0 6 eng ENG CB 26-229 90 NaN
James Ward-Prowse 10 7 70.0 21 19 90.5 33 27 81.8 66 54 81.8 226 951 8.0 0 0.1 1 3 0 0 5 eng ENG DM 25-316 90 NaN

Shot events#

[10]:
shots = fbref.read_shot_events(match_id='db261cb0')
shots.head()
[10]:
minute outcome distance body_part notes SCA 1 SCA 2
player event player event
league season game team player
ENG-Premier League 2021 2020-09-12 Crystal Palace-Southampton Crystal Palace Cheikhou Kouyaté 36 Saved 11.0 Right Foot Half volley Andros Townsend Pass (Dead) Wilfried Zaha Fouled
James McArthur 80 Off Target 8.0 Head NaN Luka Milivojević Pass (Dead) James McArthur Pass (Live)
Jordan Ayew 75 Saved 10.0 Head NaN Luka Milivojević Pass (Dead) Jordan Ayew Fouled
Scott Dann 25 Blocked 10.0 Head NaN James McCarthy Pass (Dead) NaN NaN
Wilfried Zaha 13 Goal 10.0 Right Foot Volley Andros Townsend Pass (Live) James McCarthy Interception