{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f5e5541b", "metadata": { "nbsphinx": "hidden", "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: SOCCERDATA_LOGLEVEL=ERROR\n", "env: SOCCERDATA_NOCACHE=False\n", "env: SOCCERDATA_NOSTORE=False\n" ] } ], "source": [ "%env SOCCERDATA_LOGLEVEL=ERROR\n", "%env SOCCERDATA_NOCACHE=False\n", "%env SOCCERDATA_NOSTORE=False" ] }, { "cell_type": "code", "execution_count": 2, "id": "2454afe6", "metadata": { "tags": [] }, "outputs": [], "source": [ "import soccerdata as sd" ] }, { "cell_type": "markdown", "id": "b5784f2d", "metadata": {}, "source": [ "# Understat" ] }, { "cell_type": "code", "execution_count": 3, "id": "8dab5be9", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Provides pd.DataFrames from data at https://understat.com.\n", "\n", " Data will be downloaded as necessary and cached locally in\n", " ``~/soccerdata/data/Understat``.\n", "\n", " Parameters\n", " ----------\n", " proxy : 'tor' or dict or list(dict) or callable, optional\n", " Use a proxy to hide your IP address. Valid options are:\n", " - \"tor\": Uses the Tor network. Tor should be running in\n", " the background on port 9050.\n", " - dict: A dictionary with the proxy to use. The dict should be\n", " a mapping of supported protocols to proxy addresses. For example::\n", "\n", " {\n", " 'http': 'http://10.10.1.10:3128',\n", " 'https': 'http://10.10.1.10:1080',\n", " }\n", "\n", " - list(dict): A list of proxies to choose from. A different proxy will\n", " be selected from this list after failed requests, allowing rotating\n", " proxies.\n", " - callable: A function that returns a valid proxy. This function will\n", " be called after failed requests, allowing rotating proxies.\n", " no_cache : bool\n", " If True, will not use cached data.\n", " no_store : bool\n", " If True, will not store downloaded data.\n", " data_dir : Path\n", " Path to directory where data will be cached.\n", " \n" ] } ], "source": [ "understat = sd.Understat(leagues=\"ENG-Premier League\", seasons=\"2015/2016\")\n", "print(understat.__doc__)" ] }, { "cell_type": "markdown", "id": "f791f100", "metadata": {}, "source": [ "## Leagues" ] }, { "cell_type": "code", "execution_count": 4, "id": "4dc08db7", "metadata": { "tags": [] }, "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", "
league_idurl
league
ENG-Premier League1https://understat.com/league/EPL
\n", "
" ], "text/plain": [ " league_id url\n", "league \n", "ENG-Premier League 1 https://understat.com/league/EPL" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "leagues = understat.read_leagues()\n", "leagues.head()" ] }, { "cell_type": "markdown", "id": "98881255-a906-4f4f-aeaa-788a46b9fcc1", "metadata": {}, "source": [ "## Seasons" ] }, { "cell_type": "code", "execution_count": 5, "id": "168c34f5-3035-410f-bc74-51c4af9ca4d7", "metadata": { "tags": [] }, "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", "
league_idseason_idurl
leagueseason
ENG-Premier League151612015https://understat.com/league/EPL/2015
\n", "
" ], "text/plain": [ " league_id season_id \\\n", "league season \n", "ENG-Premier League 1516 1 2015 \n", "\n", " url \n", "league season \n", "ENG-Premier League 1516 https://understat.com/league/EPL/2015 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "seasons = understat.read_seasons()\n", "seasons.head()" ] }, { "cell_type": "markdown", "id": "eb5fabf3", "metadata": {}, "source": [ "## Schedule" ] }, { "cell_type": "code", "execution_count": 6, "id": "66ce10da", "metadata": { "tags": [] }, "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", "
league_idseason_idgame_iddatehome_team_idaway_team_idhome_teamaway_teamaway_team_codehome_team_codehome_goalsaway_goalshome_xgaway_xgis_resulthas_dataurl
leagueseasongame
ENG-Premier League15162015-08-08 Bournemouth-Aston Villa12015822015-08-08 18:00:007371BournemouthAston VillaAVLBOU010.8761060.782253TrueTruehttps://understat.com/match/82
2015-08-08 Chelsea-Swansea12015862015-08-08 20:30:008084ChelseaSwanseaSWACHE220.643962.59203TrueTruehttps://understat.com/match/86
2015-08-08 Everton-Watford12015832015-08-08 18:00:007290EvertonWatfordWATEVE220.6042260.557892TrueTruehttps://understat.com/match/83
2015-08-08 Leicester-Sunderland12015842015-08-08 18:00:007577LeicesterSunderlandSUNLEI422.568031.45946TrueTruehttps://understat.com/match/84
2015-08-08 Manchester United-Tottenham12015812015-08-08 15:45:008982Manchester UnitedTottenhamTOTMUN100.6275390.6746TrueTruehttps://understat.com/match/81
\n", "
" ], "text/plain": [ " league_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 1 \n", " 2015-08-08 Chelsea-Swansea 1 \n", " 2015-08-08 Everton-Watford 1 \n", " 2015-08-08 Leicester-Sunderland 1 \n", " 2015-08-08 Manchester United-Tottenham 1 \n", "\n", " season_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 2015 \n", " 2015-08-08 Chelsea-Swansea 2015 \n", " 2015-08-08 Everton-Watford 2015 \n", " 2015-08-08 Leicester-Sunderland 2015 \n", " 2015-08-08 Manchester United-Tottenham 2015 \n", "\n", " game_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 82 \n", " 2015-08-08 Chelsea-Swansea 86 \n", " 2015-08-08 Everton-Watford 83 \n", " 2015-08-08 Leicester-Sunderland 84 \n", " 2015-08-08 Manchester United-Tottenham 81 \n", "\n", " date \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 2015-08-08 18:00:00 \n", " 2015-08-08 Chelsea-Swansea 2015-08-08 20:30:00 \n", " 2015-08-08 Everton-Watford 2015-08-08 18:00:00 \n", " 2015-08-08 Leicester-Sunderland 2015-08-08 18:00:00 \n", " 2015-08-08 Manchester United-Tottenham 2015-08-08 15:45:00 \n", "\n", " home_team_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 73 \n", " 2015-08-08 Chelsea-Swansea 80 \n", " 2015-08-08 Everton-Watford 72 \n", " 2015-08-08 Leicester-Sunderland 75 \n", " 2015-08-08 Manchester United-Tottenham 89 \n", "\n", " away_team_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 71 \n", " 2015-08-08 Chelsea-Swansea 84 \n", " 2015-08-08 Everton-Watford 90 \n", " 2015-08-08 Leicester-Sunderland 77 \n", " 2015-08-08 Manchester United-Tottenham 82 \n", "\n", " home_team \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Bournemouth \n", " 2015-08-08 Chelsea-Swansea Chelsea \n", " 2015-08-08 Everton-Watford Everton \n", " 2015-08-08 Leicester-Sunderland Leicester \n", " 2015-08-08 Manchester United-Tottenham Manchester United \n", "\n", " away_team \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa \n", " 2015-08-08 Chelsea-Swansea Swansea \n", " 2015-08-08 Everton-Watford Watford \n", " 2015-08-08 Leicester-Sunderland Sunderland \n", " 2015-08-08 Manchester United-Tottenham Tottenham \n", "\n", " away_team_code \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa AVL \n", " 2015-08-08 Chelsea-Swansea SWA \n", " 2015-08-08 Everton-Watford WAT \n", " 2015-08-08 Leicester-Sunderland SUN \n", " 2015-08-08 Manchester United-Tottenham TOT \n", "\n", " home_team_code \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa BOU \n", " 2015-08-08 Chelsea-Swansea CHE \n", " 2015-08-08 Everton-Watford EVE \n", " 2015-08-08 Leicester-Sunderland LEI \n", " 2015-08-08 Manchester United-Tottenham MUN \n", "\n", " home_goals \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0 \n", " 2015-08-08 Chelsea-Swansea 2 \n", " 2015-08-08 Everton-Watford 2 \n", " 2015-08-08 Leicester-Sunderland 4 \n", " 2015-08-08 Manchester United-Tottenham 1 \n", "\n", " away_goals \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 1 \n", " 2015-08-08 Chelsea-Swansea 2 \n", " 2015-08-08 Everton-Watford 2 \n", " 2015-08-08 Leicester-Sunderland 2 \n", " 2015-08-08 Manchester United-Tottenham 0 \n", "\n", " home_xg \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0.876106 \n", " 2015-08-08 Chelsea-Swansea 0.64396 \n", " 2015-08-08 Everton-Watford 0.604226 \n", " 2015-08-08 Leicester-Sunderland 2.56803 \n", " 2015-08-08 Manchester United-Tottenham 0.627539 \n", "\n", " away_xg \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0.782253 \n", " 2015-08-08 Chelsea-Swansea 2.59203 \n", " 2015-08-08 Everton-Watford 0.557892 \n", " 2015-08-08 Leicester-Sunderland 1.45946 \n", " 2015-08-08 Manchester United-Tottenham 0.6746 \n", "\n", " is_result \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa True \n", " 2015-08-08 Chelsea-Swansea True \n", " 2015-08-08 Everton-Watford True \n", " 2015-08-08 Leicester-Sunderland True \n", " 2015-08-08 Manchester United-Tottenham True \n", "\n", " has_data \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa True \n", " 2015-08-08 Chelsea-Swansea True \n", " 2015-08-08 Everton-Watford True \n", " 2015-08-08 Leicester-Sunderland True \n", " 2015-08-08 Manchester United-Tottenham True \n", "\n", " url \n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa https://understat.com/match/82 \n", " 2015-08-08 Chelsea-Swansea https://understat.com/match/86 \n", " 2015-08-08 Everton-Watford https://understat.com/match/83 \n", " 2015-08-08 Leicester-Sunderland https://understat.com/match/84 \n", " 2015-08-08 Manchester United-Tottenham https://understat.com/match/81 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "schedule = understat.read_schedule()\n", "schedule.head()" ] }, { "cell_type": "markdown", "id": "7bd05a01", "metadata": {}, "source": [ "## Team match stats" ] }, { "cell_type": "code", "execution_count": 7, "id": "bc789ef7", "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", "
league_idseason_idgame_iddatehome_team_idaway_team_idhome_teamaway_teamaway_team_codehome_team_code...away_ppdaaway_deep_completionshome_pointshome_expected_pointshome_goalshome_xghome_np_xghome_np_xg_differencehome_ppdahome_deep_completions
leagueseasongame
ENG-Premier League15162015-08-08 Bournemouth-Aston Villa12015822015-08-08 18:00:007371BournemouthAston VillaAVLBOU...11.846154201.391200.8761060.8761060.0938536.911
2015-08-08 Chelsea-Swansea12015862015-08-08 20:30:008084ChelseaSwanseaSWACHE...8.833333510.183620.643960.64396-1.186910.36363610
2015-08-08 Everton-Watford12015832015-08-08 18:00:007290EvertonWatfordWATEVE...17.157895411.330120.6042260.6042260.0463346.655
2015-08-08 Leicester-Sunderland12015842015-08-08 18:00:007577LeicesterSunderlandSUNLEI...9.555556632.132342.568031.806860.347410.885
2015-08-08 Manchester United-Tottenham12015812015-08-08 15:45:008982Manchester UnitedTottenhamTOTMUN...8.218751031.248210.6275390.627539-0.04706113.8260874
\n", "

5 rows × 26 columns

\n", "
" ], "text/plain": [ " league_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 1 \n", " 2015-08-08 Chelsea-Swansea 1 \n", " 2015-08-08 Everton-Watford 1 \n", " 2015-08-08 Leicester-Sunderland 1 \n", " 2015-08-08 Manchester United-Tottenham 1 \n", "\n", " season_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 2015 \n", " 2015-08-08 Chelsea-Swansea 2015 \n", " 2015-08-08 Everton-Watford 2015 \n", " 2015-08-08 Leicester-Sunderland 2015 \n", " 2015-08-08 Manchester United-Tottenham 2015 \n", "\n", " game_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 82 \n", " 2015-08-08 Chelsea-Swansea 86 \n", " 2015-08-08 Everton-Watford 83 \n", " 2015-08-08 Leicester-Sunderland 84 \n", " 2015-08-08 Manchester United-Tottenham 81 \n", "\n", " date \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 2015-08-08 18:00:00 \n", " 2015-08-08 Chelsea-Swansea 2015-08-08 20:30:00 \n", " 2015-08-08 Everton-Watford 2015-08-08 18:00:00 \n", " 2015-08-08 Leicester-Sunderland 2015-08-08 18:00:00 \n", " 2015-08-08 Manchester United-Tottenham 2015-08-08 15:45:00 \n", "\n", " home_team_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 73 \n", " 2015-08-08 Chelsea-Swansea 80 \n", " 2015-08-08 Everton-Watford 72 \n", " 2015-08-08 Leicester-Sunderland 75 \n", " 2015-08-08 Manchester United-Tottenham 89 \n", "\n", " away_team_id \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 71 \n", " 2015-08-08 Chelsea-Swansea 84 \n", " 2015-08-08 Everton-Watford 90 \n", " 2015-08-08 Leicester-Sunderland 77 \n", " 2015-08-08 Manchester United-Tottenham 82 \n", "\n", " home_team \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Bournemouth \n", " 2015-08-08 Chelsea-Swansea Chelsea \n", " 2015-08-08 Everton-Watford Everton \n", " 2015-08-08 Leicester-Sunderland Leicester \n", " 2015-08-08 Manchester United-Tottenham Manchester United \n", "\n", " away_team \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa \n", " 2015-08-08 Chelsea-Swansea Swansea \n", " 2015-08-08 Everton-Watford Watford \n", " 2015-08-08 Leicester-Sunderland Sunderland \n", " 2015-08-08 Manchester United-Tottenham Tottenham \n", "\n", " away_team_code \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa AVL \n", " 2015-08-08 Chelsea-Swansea SWA \n", " 2015-08-08 Everton-Watford WAT \n", " 2015-08-08 Leicester-Sunderland SUN \n", " 2015-08-08 Manchester United-Tottenham TOT \n", "\n", " home_team_code \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa BOU \n", " 2015-08-08 Chelsea-Swansea CHE \n", " 2015-08-08 Everton-Watford EVE \n", " 2015-08-08 Leicester-Sunderland LEI \n", " 2015-08-08 Manchester United-Tottenham MUN \n", "\n", " ... \\\n", "league season game ... \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa ... \n", " 2015-08-08 Chelsea-Swansea ... \n", " 2015-08-08 Everton-Watford ... \n", " 2015-08-08 Leicester-Sunderland ... \n", " 2015-08-08 Manchester United-Tottenham ... \n", "\n", " away_ppda \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 11.846154 \n", " 2015-08-08 Chelsea-Swansea 8.833333 \n", " 2015-08-08 Everton-Watford 17.157895 \n", " 2015-08-08 Leicester-Sunderland 9.555556 \n", " 2015-08-08 Manchester United-Tottenham 8.21875 \n", "\n", " away_deep_completions \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 2 \n", " 2015-08-08 Chelsea-Swansea 5 \n", " 2015-08-08 Everton-Watford 4 \n", " 2015-08-08 Leicester-Sunderland 6 \n", " 2015-08-08 Manchester United-Tottenham 10 \n", "\n", " home_points \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0 \n", " 2015-08-08 Chelsea-Swansea 1 \n", " 2015-08-08 Everton-Watford 1 \n", " 2015-08-08 Leicester-Sunderland 3 \n", " 2015-08-08 Manchester United-Tottenham 3 \n", "\n", " home_expected_points \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 1.3912 \n", " 2015-08-08 Chelsea-Swansea 0.1836 \n", " 2015-08-08 Everton-Watford 1.3301 \n", " 2015-08-08 Leicester-Sunderland 2.1323 \n", " 2015-08-08 Manchester United-Tottenham 1.2482 \n", "\n", " home_goals \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0 \n", " 2015-08-08 Chelsea-Swansea 2 \n", " 2015-08-08 Everton-Watford 2 \n", " 2015-08-08 Leicester-Sunderland 4 \n", " 2015-08-08 Manchester United-Tottenham 1 \n", "\n", " home_xg \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0.876106 \n", " 2015-08-08 Chelsea-Swansea 0.64396 \n", " 2015-08-08 Everton-Watford 0.604226 \n", " 2015-08-08 Leicester-Sunderland 2.56803 \n", " 2015-08-08 Manchester United-Tottenham 0.627539 \n", "\n", " home_np_xg \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0.876106 \n", " 2015-08-08 Chelsea-Swansea 0.64396 \n", " 2015-08-08 Everton-Watford 0.604226 \n", " 2015-08-08 Leicester-Sunderland 1.80686 \n", " 2015-08-08 Manchester United-Tottenham 0.627539 \n", "\n", " home_np_xg_difference \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 0.093853 \n", " 2015-08-08 Chelsea-Swansea -1.1869 \n", " 2015-08-08 Everton-Watford 0.046334 \n", " 2015-08-08 Leicester-Sunderland 0.3474 \n", " 2015-08-08 Manchester United-Tottenham -0.047061 \n", "\n", " home_ppda \\\n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 6.9 \n", " 2015-08-08 Chelsea-Swansea 10.363636 \n", " 2015-08-08 Everton-Watford 6.65 \n", " 2015-08-08 Leicester-Sunderland 10.88 \n", " 2015-08-08 Manchester United-Tottenham 13.826087 \n", "\n", " home_deep_completions \n", "league season game \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa 11 \n", " 2015-08-08 Chelsea-Swansea 10 \n", " 2015-08-08 Everton-Watford 5 \n", " 2015-08-08 Leicester-Sunderland 5 \n", " 2015-08-08 Manchester United-Tottenham 4 \n", "\n", "[5 rows x 26 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "team_match_stats = understat.read_team_match_stats()\n", "team_match_stats.head()" ] }, { "cell_type": "markdown", "id": "7c07e843", "metadata": {}, "source": [ "## Player season stats" ] }, { "cell_type": "code", "execution_count": 8, "id": "4b9cb8d8", "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", "
league_idseason_idteamteam_idplayer_idpositionmatchesminutesgoalsxgnp_goalsnp_xgassistsxashotskey_passesyellow_cardsred_cardsxg_chainxg_buildup
leagueseasonplayer
ENG-Premier League1516Aaron Cresswell12015West Ham81534D M37331921.09256321.09256343.29461828401010.3393676.831139
Aaron Lennon12015Everton72593F M S25153452.22609552.22609501.6979511823105.5353921.90374
Aaron Ramsey12015Arsenal83504M S31262458.61432358.61432344.04624269374023.28256614.176444
Abdul Rahman Baba12015Chelsea80684D S15101800.37911500.37911510.17924163103.8696693.490554
Adam Bogdan12015Liverpool87698GK218000.000.000.000000.1202160.120216
\n", "
" ], "text/plain": [ " league_id season_id team \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 1 2015 West Ham \n", " Aaron Lennon 1 2015 Everton \n", " Aaron Ramsey 1 2015 Arsenal \n", " Abdul Rahman Baba 1 2015 Chelsea \n", " Adam Bogdan 1 2015 Liverpool \n", "\n", " team_id player_id position \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 81 534 D M \n", " Aaron Lennon 72 593 F M S \n", " Aaron Ramsey 83 504 M S \n", " Abdul Rahman Baba 80 684 D S \n", " Adam Bogdan 87 698 GK \n", "\n", " matches minutes goals \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 37 3319 2 \n", " Aaron Lennon 25 1534 5 \n", " Aaron Ramsey 31 2624 5 \n", " Abdul Rahman Baba 15 1018 0 \n", " Adam Bogdan 2 180 0 \n", "\n", " xg np_goals np_xg \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 1.092563 2 1.092563 \n", " Aaron Lennon 2.226095 5 2.226095 \n", " Aaron Ramsey 8.614323 5 8.614323 \n", " Abdul Rahman Baba 0.379115 0 0.379115 \n", " Adam Bogdan 0.0 0 0.0 \n", "\n", " assists xa shots \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 4 3.294618 28 \n", " Aaron Lennon 0 1.697951 18 \n", " Aaron Ramsey 4 4.046242 69 \n", " Abdul Rahman Baba 1 0.179241 6 \n", " Adam Bogdan 0 0.0 0 \n", "\n", " key_passes yellow_cards \\\n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 40 1 \n", " Aaron Lennon 23 1 \n", " Aaron Ramsey 37 4 \n", " Abdul Rahman Baba 3 1 \n", " Adam Bogdan 0 0 \n", "\n", " red_cards xg_chain xg_buildup \n", "league season player \n", "ENG-Premier League 1516 Aaron Cresswell 0 10.339367 6.831139 \n", " Aaron Lennon 0 5.535392 1.90374 \n", " Aaron Ramsey 0 23.282566 14.176444 \n", " Abdul Rahman Baba 0 3.869669 3.490554 \n", " Adam Bogdan 0 0.120216 0.120216 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "player_season_stats = understat.read_player_season_stats()\n", "player_season_stats.head()" ] }, { "cell_type": "markdown", "id": "04162974", "metadata": {}, "source": [ "## Player match stats" ] }, { "cell_type": "code", "execution_count": 9, "id": "5ef60999", "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", "
league_idseason_idgame_idteam_idplayer_idpositionposition_idminutesgoalsown_goalsshotsxgxaxg_chainxg_buildup
leagueseasongameteamplayer
ENG-Premier League15162015-08-08 Bournemouth-Aston VillaAston VillaAshley Westwood120158271669MC9900000.00.3740820.1319370.131937
Brad Guzan120158271662GK1900000.00.00.00.0
Carlos Sánchez120158271667Sub17180000.00.00.00.0
Ciaran Clark120158271875DC3900000.00.00.1319370.131937
Gabriel Agbonlahor120158271890FW15900020.130160.1136680.2438280.0
\n", "
" ], "text/plain": [ " league_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 1 \n", " Brad Guzan 1 \n", " Carlos Sánchez 1 \n", " Ciaran Clark 1 \n", " Gabriel Agbonlahor 1 \n", "\n", " season_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 2015 \n", " Brad Guzan 2015 \n", " Carlos Sánchez 2015 \n", " Ciaran Clark 2015 \n", " Gabriel Agbonlahor 2015 \n", "\n", " game_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 82 \n", " Brad Guzan 82 \n", " Carlos Sánchez 82 \n", " Ciaran Clark 82 \n", " Gabriel Agbonlahor 82 \n", "\n", " team_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 71 \n", " Brad Guzan 71 \n", " Carlos Sánchez 71 \n", " Ciaran Clark 71 \n", " Gabriel Agbonlahor 71 \n", "\n", " player_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 669 \n", " Brad Guzan 662 \n", " Carlos Sánchez 667 \n", " Ciaran Clark 875 \n", " Gabriel Agbonlahor 890 \n", "\n", " position \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood MC \n", " Brad Guzan GK \n", " Carlos Sánchez Sub \n", " Ciaran Clark DC \n", " Gabriel Agbonlahor FW \n", "\n", " position_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 9 \n", " Brad Guzan 1 \n", " Carlos Sánchez 17 \n", " Ciaran Clark 3 \n", " Gabriel Agbonlahor 15 \n", "\n", " minutes \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 90 \n", " Brad Guzan 90 \n", " Carlos Sánchez 18 \n", " Ciaran Clark 90 \n", " Gabriel Agbonlahor 90 \n", "\n", " goals \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0 \n", " Brad Guzan 0 \n", " Carlos Sánchez 0 \n", " Ciaran Clark 0 \n", " Gabriel Agbonlahor 0 \n", "\n", " own_goals \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0 \n", " Brad Guzan 0 \n", " Carlos Sánchez 0 \n", " Ciaran Clark 0 \n", " Gabriel Agbonlahor 0 \n", "\n", " shots \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0 \n", " Brad Guzan 0 \n", " Carlos Sánchez 0 \n", " Ciaran Clark 0 \n", " Gabriel Agbonlahor 2 \n", "\n", " xg \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0.0 \n", " Brad Guzan 0.0 \n", " Carlos Sánchez 0.0 \n", " Ciaran Clark 0.0 \n", " Gabriel Agbonlahor 0.13016 \n", "\n", " xa \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0.374082 \n", " Brad Guzan 0.0 \n", " Carlos Sánchez 0.0 \n", " Ciaran Clark 0.0 \n", " Gabriel Agbonlahor 0.113668 \n", "\n", " xg_chain \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0.131937 \n", " Brad Guzan 0.0 \n", " Carlos Sánchez 0.0 \n", " Ciaran Clark 0.131937 \n", " Gabriel Agbonlahor 0.243828 \n", "\n", " xg_buildup \n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Ashley Westwood 0.131937 \n", " Brad Guzan 0.0 \n", " Carlos Sánchez 0.0 \n", " Ciaran Clark 0.131937 \n", " Gabriel Agbonlahor 0.0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "player_match_stats = understat.read_player_match_stats()\n", "player_match_stats.head()" ] }, { "cell_type": "markdown", "id": "6da5002a", "metadata": {}, "source": [ "## Shot events" ] }, { "cell_type": "code", "execution_count": 10, "id": "aad9366c", "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", "
league_idseason_idgame_iddateshot_idteam_idplayer_idassist_player_idassist_playerxglocation_xlocation_yminutebody_partsituationresult
leagueseasongameteamplayer
ENG-Premier League15162015-08-08 Bournemouth-Aston VillaAston VillaGabriel Agbonlahor12015822015-08-08 18:00:0048714671890<NA><NA>0.0754840.860.50367Left FootOpen PlayBlocked Shot
Gabriel Agbonlahor12015822015-08-08 18:00:0048715071890548651Micah Richards0.0546760.7950.50781Left FootOpen PlaySaved Shot
Idrissa Gueye12015822015-08-08 18:00:0048713671668548653Jordan Veretout0.0182690.7420.59826Right FootOpen PlayMissed Shot
Idrissa Gueye12015822015-08-08 18:00:0048714471668548657Gabriel Agbonlahor0.1136680.8830.56147Left FootOpen PlaySaved Shot
Leandro Bacuna12015822015-08-08 18:00:0048714171674<NA><NA>0.0973710.7860.43742Right FootDirect FreekickBlocked Shot
\n", "
" ], "text/plain": [ " league_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 1 \n", " Gabriel Agbonlahor 1 \n", " Idrissa Gueye 1 \n", " Idrissa Gueye 1 \n", " Leandro Bacuna 1 \n", "\n", " season_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 2015 \n", " Gabriel Agbonlahor 2015 \n", " Idrissa Gueye 2015 \n", " Idrissa Gueye 2015 \n", " Leandro Bacuna 2015 \n", "\n", " game_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 82 \n", " Gabriel Agbonlahor 82 \n", " Idrissa Gueye 82 \n", " Idrissa Gueye 82 \n", " Leandro Bacuna 82 \n", "\n", " date \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 2015-08-08 18:00:00 \n", " Gabriel Agbonlahor 2015-08-08 18:00:00 \n", " Idrissa Gueye 2015-08-08 18:00:00 \n", " Idrissa Gueye 2015-08-08 18:00:00 \n", " Leandro Bacuna 2015-08-08 18:00:00 \n", "\n", " shot_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 487146 \n", " Gabriel Agbonlahor 487150 \n", " Idrissa Gueye 487136 \n", " Idrissa Gueye 487144 \n", " Leandro Bacuna 487141 \n", "\n", " team_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 71 \n", " Gabriel Agbonlahor 71 \n", " Idrissa Gueye 71 \n", " Idrissa Gueye 71 \n", " Leandro Bacuna 71 \n", "\n", " player_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 890 \n", " Gabriel Agbonlahor 890 \n", " Idrissa Gueye 668 \n", " Idrissa Gueye 668 \n", " Leandro Bacuna 674 \n", "\n", " assist_player_id \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor \n", " Gabriel Agbonlahor 548651 \n", " Idrissa Gueye 548653 \n", " Idrissa Gueye 548657 \n", " Leandro Bacuna \n", "\n", " assist_player \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor \n", " Gabriel Agbonlahor Micah Richards \n", " Idrissa Gueye Jordan Veretout \n", " Idrissa Gueye Gabriel Agbonlahor \n", " Leandro Bacuna \n", "\n", " xg \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 0.075484 \n", " Gabriel Agbonlahor 0.054676 \n", " Idrissa Gueye 0.018269 \n", " Idrissa Gueye 0.113668 \n", " Leandro Bacuna 0.097371 \n", "\n", " location_x \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 0.86 \n", " Gabriel Agbonlahor 0.795 \n", " Idrissa Gueye 0.742 \n", " Idrissa Gueye 0.883 \n", " Leandro Bacuna 0.786 \n", "\n", " location_y \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 0.503 \n", " Gabriel Agbonlahor 0.507 \n", " Idrissa Gueye 0.598 \n", " Idrissa Gueye 0.561 \n", " Leandro Bacuna 0.437 \n", "\n", " minute \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor 67 \n", " Gabriel Agbonlahor 81 \n", " Idrissa Gueye 26 \n", " Idrissa Gueye 47 \n", " Leandro Bacuna 42 \n", "\n", " body_part \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor Left Foot \n", " Gabriel Agbonlahor Left Foot \n", " Idrissa Gueye Right Foot \n", " Idrissa Gueye Left Foot \n", " Leandro Bacuna Right Foot \n", "\n", " situation \\\n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor Open Play \n", " Gabriel Agbonlahor Open Play \n", " Idrissa Gueye Open Play \n", " Idrissa Gueye Open Play \n", " Leandro Bacuna Direct Freekick \n", "\n", " result \n", "league season game team player \n", "ENG-Premier League 1516 2015-08-08 Bournemouth-Aston Villa Aston Villa Gabriel Agbonlahor Blocked Shot \n", " Gabriel Agbonlahor Saved Shot \n", " Idrissa Gueye Missed Shot \n", " Idrissa Gueye Saved Shot \n", " Leandro Bacuna Blocked Shot " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "shot_events = understat.read_shot_events()\n", "shot_events.head()" ] } ], "metadata": { "kernelspec": { "display_name": "soccerdata", "language": "python", "name": "soccerdata" }, "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.12.1" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 5 }