{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e621e3ae", "metadata": { "nbsphinx": "hidden" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: SOCCERDATA_LOGLEVEL=ERROR\n", "env: SOCCERDATA_NOCACHE=True\n", "env: SOCCERDATA_NOSTORE=True\n" ] } ], "source": [ "%env SOCCERDATA_LOGLEVEL=ERROR\n", "%env SOCCERDATA_NOCACHE=True\n", "%env SOCCERDATA_NOSTORE=True" ] }, { "cell_type": "code", "execution_count": 2, "id": "2454afe6", "metadata": {}, "outputs": [], "source": [ "import soccerdata as sd" ] }, { "cell_type": "markdown", "id": "b5784f2d", "metadata": {}, "source": [ "# ESPN" ] }, { "cell_type": "code", "execution_count": 3, "id": "8dab5be9", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/cw/dtaijupiter/NoCsBack/dtai/pieterr/Projects/soccerdata/soccerdata/_common.py:466: UserWarning: Season id \"2021\" is ambiguous: interpreting as \"20-21\"\n", " warnings.warn(msg)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Provides pd.DataFrames from JSON api available at http://site.api.espn.com.\n", "\n", " Data will be downloaded as necessary and cached locally in\n", " ``~/soccerdata/data/ESPN``.\n", "\n", " Parameters\n", " ----------\n", " leagues : string or iterable, optional\n", " IDs of leagues to include.\n", "\n", " seasons : string, int or list, optional\n", " Seasons to include. Supports multiple formats.\n", " Examples: '16-17'; 2016; '2016-17'; [14, 15, 16]\n", " proxy : 'tor' or 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": [ "espn = sd.ESPN(leagues=\"ENG-Premier League\", seasons=2021)\n", "print(espn.__doc__)" ] }, { "cell_type": "markdown", "id": "3a4c2916", "metadata": {}, "source": [ "## Game schedule" ] }, { "cell_type": "code", "execution_count": 4, "id": "745be31a", "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", "
datehome_teamaway_teamgame_idleague_id
leagueseasongame
ENG-Premier League20212019-08-09 Liverpool-Norwich City2019-08-09 19:00:00+00:00LiverpoolNorwich City541844eng.1
2019-08-10 AFC Bournemouth-Sheffield United2019-08-10 14:00:00+00:00AFC BournemouthSheffield United541840eng.1
2019-08-10 Burnley-Southampton2019-08-10 14:00:00+00:00BurnleySouthampton541841eng.1
2019-08-10 Crystal Palace-Everton2019-08-10 14:00:00+00:00Crystal PalaceEverton541839eng.1
2019-08-10 Tottenham Hotspur-Aston Villa2019-08-10 16:30:00+00:00Tottenham HotspurAston Villa541837eng.1
\n", "
" ], "text/plain": [ " date \\\n", "league season game \n", "ENG-Premier League 2021 2019-08-09 Liverpool-Norwich City 2019-08-09 19:00:00+00:00 \n", " 2019-08-10 AFC Bournemouth-Sheffield United 2019-08-10 14:00:00+00:00 \n", " 2019-08-10 Burnley-Southampton 2019-08-10 14:00:00+00:00 \n", " 2019-08-10 Crystal Palace-Everton 2019-08-10 14:00:00+00:00 \n", " 2019-08-10 Tottenham Hotspur-Aston Villa 2019-08-10 16:30:00+00:00 \n", "\n", " home_team \\\n", "league season game \n", "ENG-Premier League 2021 2019-08-09 Liverpool-Norwich City Liverpool \n", " 2019-08-10 AFC Bournemouth-Sheffield United AFC Bournemouth \n", " 2019-08-10 Burnley-Southampton Burnley \n", " 2019-08-10 Crystal Palace-Everton Crystal Palace \n", " 2019-08-10 Tottenham Hotspur-Aston Villa Tottenham Hotspur \n", "\n", " away_team \\\n", "league season game \n", "ENG-Premier League 2021 2019-08-09 Liverpool-Norwich City Norwich City \n", " 2019-08-10 AFC Bournemouth-Sheffield United Sheffield United \n", " 2019-08-10 Burnley-Southampton Southampton \n", " 2019-08-10 Crystal Palace-Everton Everton \n", " 2019-08-10 Tottenham Hotspur-Aston Villa Aston Villa \n", "\n", " game_id \\\n", "league season game \n", "ENG-Premier League 2021 2019-08-09 Liverpool-Norwich City 541844 \n", " 2019-08-10 AFC Bournemouth-Sheffield United 541840 \n", " 2019-08-10 Burnley-Southampton 541841 \n", " 2019-08-10 Crystal Palace-Everton 541839 \n", " 2019-08-10 Tottenham Hotspur-Aston Villa 541837 \n", "\n", " league_id \n", "league season game \n", "ENG-Premier League 2021 2019-08-09 Liverpool-Norwich City eng.1 \n", " 2019-08-10 AFC Bournemouth-Sheffield United eng.1 \n", " 2019-08-10 Burnley-Southampton eng.1 \n", " 2019-08-10 Crystal Palace-Everton eng.1 \n", " 2019-08-10 Tottenham Hotspur-Aston Villa eng.1 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "epl_schedule = espn.read_schedule()\n", "epl_schedule.head()" ] }, { "cell_type": "markdown", "id": "246ca661", "metadata": {}, "source": [ "## Match sheet data" ] }, { "cell_type": "code", "execution_count": 5, "id": "1c87e14a", "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", "
is_homevenueattendancecapacityrosterfouls_committedyellow_cardsred_cardsoffsideswon_cornerssavespossession_pcttotal_shotsshots_on_target
leagueseasongameteam
ENG-Premier League20212020-07-26 West Ham United-Aston VillaAston VillaFalseNone0None[{'active': True, 'starter': True, 'jersey': '...162000363101
West Ham UnitedTrueNone0None[{'active': True, 'starter': True, 'jersey': '...131017037134
\n", "
" ], "text/plain": [ " is_home \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa False \n", " West Ham United True \n", "\n", " venue \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa None \n", " West Ham United None \n", "\n", " attendance \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 0 \n", " West Ham United 0 \n", "\n", " capacity \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa None \n", " West Ham United None \n", "\n", " roster \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa [{'active': True, 'starter': True, 'jersey': '... \n", " West Ham United [{'active': True, 'starter': True, 'jersey': '... \n", "\n", " fouls_committed \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 16 \n", " West Ham United 13 \n", "\n", " yellow_cards \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 2 \n", " West Ham United 1 \n", "\n", " red_cards \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 0 \n", " West Ham United 0 \n", "\n", " offsides \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 0 \n", " West Ham United 1 \n", "\n", " won_corners \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 0 \n", " West Ham United 7 \n", "\n", " saves \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 3 \n", " West Ham United 0 \n", "\n", " possession_pct \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 63 \n", " West Ham United 37 \n", "\n", " total_shots \\\n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 10 \n", " West Ham United 13 \n", "\n", " shots_on_target \n", "league season game team \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa 1 \n", " West Ham United 4 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matchsheet = espn.read_matchsheet(match_id=541465)\n", "matchsheet.head()" ] }, { "cell_type": "markdown", "id": "69ea8672", "metadata": {}, "source": [ "## Line ups" ] }, { "cell_type": "code", "execution_count": 6, "id": "48f9453e", "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", "
is_homepositionformation_placesub_insub_outappearancesfouls_committedfouls_sufferedown_goalsred_cardssub_insyellow_cardsgoal_assistsshots_on_targettotal_goalstotal_shotsgoals_concededsavesshots_facedoffsides
leagueseasongameteamplayer
ENG-Premier League20212020-07-26 West Ham United-Aston VillaAston VillaAnwar El GhaziFalseSubstitute090end1.00.00.00.00.01.00.00.00.00.00.00.0NaN0.00.0
Conor HourihaneFalseCenter Left Midfielder10start761.00.01.00.00.00.00.00.00.00.00.00.0NaN0.00.0
Douglas LuizFalseDefensive Midfielder4startend1.02.02.00.00.00.00.00.00.00.00.01.0NaN0.00.0
Ezri KonsaFalseCenter Right Defender5startend1.00.00.00.00.00.00.00.00.00.00.01.0NaN0.00.0
Frédéric GuilbertFalseRight Back2start761.01.01.00.00.00.00.00.00.00.00.00.0NaN0.00.0
\n", "
" ], "text/plain": [ " is_home \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi False \n", " Conor Hourihane False \n", " Douglas Luiz False \n", " Ezri Konsa False \n", " Frédéric Guilbert False \n", "\n", " position \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi Substitute \n", " Conor Hourihane Center Left Midfielder \n", " Douglas Luiz Defensive Midfielder \n", " Ezri Konsa Center Right Defender \n", " Frédéric Guilbert Right Back \n", "\n", " formation_place \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0 \n", " Conor Hourihane 10 \n", " Douglas Luiz 4 \n", " Ezri Konsa 5 \n", " Frédéric Guilbert 2 \n", "\n", " sub_in \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 90 \n", " Conor Hourihane start \n", " Douglas Luiz start \n", " Ezri Konsa start \n", " Frédéric Guilbert start \n", "\n", " sub_out \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi end \n", " Conor Hourihane 76 \n", " Douglas Luiz end \n", " Ezri Konsa end \n", " Frédéric Guilbert 76 \n", "\n", " appearances \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 1.0 \n", " Conor Hourihane 1.0 \n", " Douglas Luiz 1.0 \n", " Ezri Konsa 1.0 \n", " Frédéric Guilbert 1.0 \n", "\n", " fouls_committed \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 2.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 1.0 \n", "\n", " fouls_suffered \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 1.0 \n", " Douglas Luiz 2.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 1.0 \n", "\n", " own_goals \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " red_cards \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " sub_ins \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 1.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " yellow_cards \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " goal_assists \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " shots_on_target \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " total_goals \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " total_shots \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " goals_conceded \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 1.0 \n", " Ezri Konsa 1.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " saves \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi NaN \n", " Conor Hourihane NaN \n", " Douglas Luiz NaN \n", " Ezri Konsa NaN \n", " Frédéric Guilbert NaN \n", "\n", " shots_faced \\\n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 \n", "\n", " offsides \n", "league season game team player \n", "ENG-Premier League 2021 2020-07-26 West Ham United-Aston Villa Aston Villa Anwar El Ghazi 0.0 \n", " Conor Hourihane 0.0 \n", " Douglas Luiz 0.0 \n", " Ezri Konsa 0.0 \n", " Frédéric Guilbert 0.0 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lineups = espn.read_lineup(match_id=541465)\n", "lineups.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.9.6" }, "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 }