{ "cells": [ { "cell_type": "markdown", "id": "1ee69dc3-2f18-4110-a232-81d807884da9", "metadata": {}, "source": [ "# Understat" ] }, { "cell_type": "code", "execution_count": 1, "id": "2077b457-872d-420d-8799-9457e1a8f50f", "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "sys.path.append(\"../../\")\n", "\n", "import penaltyblog as pb" ] }, { "cell_type": "markdown", "id": "56a9acc8-bf3a-4b1d-becb-f9b1e9ca1a09", "metadata": {}, "source": [ "## List available competitions" ] }, { "cell_type": "code", "execution_count": 2, "id": "bea88bf4-476f-4445-9345-379795d85025", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['DEU Bundesliga 1',\n", " 'ENG Premier League',\n", " 'ESP La Liga',\n", " 'FRA Ligue 1',\n", " 'ITA Serie A',\n", " 'RUS Premier League']" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pb.scrapers.Understat.list_competitions()" ] }, { "cell_type": "markdown", "id": "c22b88a5-d0bc-4553-a1b6-700c630a36a7", "metadata": {}, "source": [ "## Get Fixtures" ] }, { "cell_type": "code", "execution_count": 3, "id": "88b75ca5-90dd-4a6e-a0b4-4b1a5a63fec2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>understat_id</th>\n", " <th>datetime</th>\n", " <th>team_home</th>\n", " <th>team_away</th>\n", " <th>goals_home</th>\n", " <th>goals_away</th>\n", " <th>xg_home</th>\n", " <th>xg_away</th>\n", " <th>forecast_w</th>\n", " <th>forecast_d</th>\n", " <th>forecast_l</th>\n", " <th>season</th>\n", " <th>competition</th>\n", " <th>date</th>\n", " </tr>\n", " <tr>\n", " <th>id</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>1628812800---brentford---arsenal</th>\n", " <td>16376</td>\n", " <td>2021-08-13 19:00:00</td>\n", " <td>Brentford</td>\n", " <td>Arsenal</td>\n", " <td>2</td>\n", " <td>0</td>\n", " <td>1.888180</td>\n", " <td>1.023850</td>\n", " <td>0.6289</td>\n", " <td>0.2287</td>\n", " <td>0.1424</td>\n", " <td>2021-2022</td>\n", " <td>ENG Premier League</td>\n", " <td>2021-08-13</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---burnley---brighton</th>\n", " <td>16378</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>Burnley</td>\n", " <td>Brighton</td>\n", " <td>1</td>\n", " <td>2</td>\n", " <td>1.795480</td>\n", " <td>1.685300</td>\n", " <td>0.3894</td>\n", " <td>0.2877</td>\n", " <td>0.3229</td>\n", " <td>2021-2022</td>\n", " <td>ENG Premier League</td>\n", " <td>2021-08-14</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---chelsea---crystal_palace</th>\n", " <td>16379</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>Chelsea</td>\n", " <td>Crystal Palace</td>\n", " <td>3</td>\n", " <td>0</td>\n", " <td>1.187090</td>\n", " <td>0.321701</td>\n", " <td>0.6405</td>\n", " <td>0.2822</td>\n", " <td>0.0773</td>\n", " <td>2021-2022</td>\n", " <td>ENG Premier League</td>\n", " <td>2021-08-14</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>16380</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2.388630</td>\n", " <td>0.580601</td>\n", " <td>0.8359</td>\n", " <td>0.1234</td>\n", " <td>0.0407</td>\n", " <td>2021-2022</td>\n", " <td>ENG Premier League</td>\n", " <td>2021-08-14</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---leicester---wolverhampton_wanderers</th>\n", " <td>16381</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>Leicester</td>\n", " <td>Wolverhampton Wanderers</td>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>0.668082</td>\n", " <td>1.327140</td>\n", " <td>0.1683</td>\n", " <td>0.2750</td>\n", " <td>0.5567</td>\n", " <td>2021-2022</td>\n", " <td>ENG Premier League</td>\n", " <td>2021-08-14</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " understat_id \\\n", "id \n", "1628812800---brentford---arsenal 16376 \n", "1628899200---burnley---brighton 16378 \n", "1628899200---chelsea---crystal_palace 16379 \n", "1628899200---everton---southampton 16380 \n", "1628899200---leicester---wolverhampton_wanderers 16381 \n", "\n", " datetime \\\n", "id \n", "1628812800---brentford---arsenal 2021-08-13 19:00:00 \n", "1628899200---burnley---brighton 2021-08-14 14:00:00 \n", "1628899200---chelsea---crystal_palace 2021-08-14 14:00:00 \n", "1628899200---everton---southampton 2021-08-14 14:00:00 \n", "1628899200---leicester---wolverhampton_wanderers 2021-08-14 14:00:00 \n", "\n", " team_home \\\n", "id \n", "1628812800---brentford---arsenal Brentford \n", "1628899200---burnley---brighton Burnley \n", "1628899200---chelsea---crystal_palace Chelsea \n", "1628899200---everton---southampton Everton \n", "1628899200---leicester---wolverhampton_wanderers Leicester \n", "\n", " team_away \\\n", "id \n", "1628812800---brentford---arsenal Arsenal \n", "1628899200---burnley---brighton Brighton \n", "1628899200---chelsea---crystal_palace Crystal Palace \n", "1628899200---everton---southampton Southampton \n", "1628899200---leicester---wolverhampton_wanderers Wolverhampton Wanderers \n", "\n", " goals_home goals_away \\\n", "id \n", "1628812800---brentford---arsenal 2 0 \n", "1628899200---burnley---brighton 1 2 \n", "1628899200---chelsea---crystal_palace 3 0 \n", "1628899200---everton---southampton 3 1 \n", "1628899200---leicester---wolverhampton_wanderers 1 0 \n", "\n", " xg_home xg_away \\\n", "id \n", "1628812800---brentford---arsenal 1.888180 1.023850 \n", "1628899200---burnley---brighton 1.795480 1.685300 \n", "1628899200---chelsea---crystal_palace 1.187090 0.321701 \n", "1628899200---everton---southampton 2.388630 0.580601 \n", "1628899200---leicester---wolverhampton_wanderers 0.668082 1.327140 \n", "\n", " forecast_w forecast_d \\\n", "id \n", "1628812800---brentford---arsenal 0.6289 0.2287 \n", "1628899200---burnley---brighton 0.3894 0.2877 \n", "1628899200---chelsea---crystal_palace 0.6405 0.2822 \n", "1628899200---everton---southampton 0.8359 0.1234 \n", "1628899200---leicester---wolverhampton_wanderers 0.1683 0.2750 \n", "\n", " forecast_l season \\\n", "id \n", "1628812800---brentford---arsenal 0.1424 2021-2022 \n", "1628899200---burnley---brighton 0.3229 2021-2022 \n", "1628899200---chelsea---crystal_palace 0.0773 2021-2022 \n", "1628899200---everton---southampton 0.0407 2021-2022 \n", "1628899200---leicester---wolverhampton_wanderers 0.5567 2021-2022 \n", "\n", " competition \\\n", "id \n", "1628812800---brentford---arsenal ENG Premier League \n", "1628899200---burnley---brighton ENG Premier League \n", "1628899200---chelsea---crystal_palace ENG Premier League \n", "1628899200---everton---southampton ENG Premier League \n", "1628899200---leicester---wolverhampton_wanderers ENG Premier League \n", "\n", " date \n", "id \n", "1628812800---brentford---arsenal 2021-08-13 \n", "1628899200---burnley---brighton 2021-08-14 \n", "1628899200---chelsea---crystal_palace 2021-08-14 \n", "1628899200---everton---southampton 2021-08-14 \n", "1628899200---leicester---wolverhampton_wanderers 2021-08-14 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "under = pb.scrapers.Understat(\"ENG Premier League\", \"2021-2022\")\n", "df = under.get_fixtures()\n", "df.head()" ] }, { "cell_type": "markdown", "id": "99cf8346-4d24-46f2-9217-7425e96dee69", "metadata": {}, "source": [ "## Get shots from a specific match (using the `understat_id` from the fixtures)" ] }, { "cell_type": "code", "execution_count": 4, "id": "2338420d-9f0b-492a-b827-6074fa21fde5", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>competition</th>\n", " <th>season</th>\n", " <th>datetime</th>\n", " <th>minute</th>\n", " <th>result</th>\n", " <th>x</th>\n", " <th>y</th>\n", " <th>x_g</th>\n", " <th>player</th>\n", " <th>h_a</th>\n", " <th>...</th>\n", " <th>situation</th>\n", " <th>shot_type</th>\n", " <th>match_id</th>\n", " <th>team_home</th>\n", " <th>team_away</th>\n", " <th>goals_home</th>\n", " <th>goals_away</th>\n", " <th>date</th>\n", " <th>player_assisted</th>\n", " <th>last_action</th>\n", " </tr>\n", " <tr>\n", " <th>id</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>2</td>\n", " <td>SavedShot</td>\n", " <td>0.8059999847412109</td>\n", " <td>0.37099998474121093</td>\n", " <td>0.03489129990339279</td>\n", " <td>Allan</td>\n", " <td>h</td>\n", " <td>...</td>\n", " <td>OpenPlay</td>\n", " <td>RightFoot</td>\n", " <td>16380</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2021-08-14</td>\n", " <td>None</td>\n", " <td>None</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>9</td>\n", " <td>MissedShots</td>\n", " <td>0.9580000305175781</td>\n", " <td>0.45799999237060546</td>\n", " <td>0.11126399785280228</td>\n", " <td>Dominic Calvert-Lewin</td>\n", " <td>h</td>\n", " <td>...</td>\n", " <td>OpenPlay</td>\n", " <td>Head</td>\n", " <td>16380</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2021-08-14</td>\n", " <td>Demarai Gray</td>\n", " <td>Aerial</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>33</td>\n", " <td>BlockedShot</td>\n", " <td>0.784000015258789</td>\n", " <td>0.40900001525878904</td>\n", " <td>0.08816669881343842</td>\n", " <td>Lucas Digne</td>\n", " <td>h</td>\n", " <td>...</td>\n", " <td>DirectFreekick</td>\n", " <td>LeftFoot</td>\n", " <td>16380</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2021-08-14</td>\n", " <td>None</td>\n", " <td>Standard</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>34</td>\n", " <td>MissedShots</td>\n", " <td>0.9409999847412109</td>\n", " <td>0.5270000076293946</td>\n", " <td>0.09325270354747772</td>\n", " <td>Dominic Calvert-Lewin</td>\n", " <td>h</td>\n", " <td>...</td>\n", " <td>OpenPlay</td>\n", " <td>Head</td>\n", " <td>16380</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2021-08-14</td>\n", " <td>Andros Townsend</td>\n", " <td>Cross</td>\n", " </tr>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>43</td>\n", " <td>MissedShots</td>\n", " <td>0.774000015258789</td>\n", " <td>0.645</td>\n", " <td>0.01725040003657341</td>\n", " <td>Lucas Digne</td>\n", " <td>h</td>\n", " <td>...</td>\n", " <td>FromCorner</td>\n", " <td>LeftFoot</td>\n", " <td>16380</td>\n", " <td>Everton</td>\n", " <td>Southampton</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>2021-08-14</td>\n", " <td>None</td>\n", " <td>None</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>5 rows أ— 21 columns</p>\n", "</div>" ], "text/plain": [ " competition season \\\n", "id \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "\n", " datetime minute result \\\n", "id \n", "1628899200---everton---southampton 2021-08-14 14:00:00 2 SavedShot \n", "1628899200---everton---southampton 2021-08-14 14:00:00 9 MissedShots \n", "1628899200---everton---southampton 2021-08-14 14:00:00 33 BlockedShot \n", "1628899200---everton---southampton 2021-08-14 14:00:00 34 MissedShots \n", "1628899200---everton---southampton 2021-08-14 14:00:00 43 MissedShots \n", "\n", " x y \\\n", "id \n", "1628899200---everton---southampton 0.8059999847412109 0.37099998474121093 \n", "1628899200---everton---southampton 0.9580000305175781 0.45799999237060546 \n", "1628899200---everton---southampton 0.784000015258789 0.40900001525878904 \n", "1628899200---everton---southampton 0.9409999847412109 0.5270000076293946 \n", "1628899200---everton---southampton 0.774000015258789 0.645 \n", "\n", " x_g \\\n", "id \n", "1628899200---everton---southampton 0.03489129990339279 \n", "1628899200---everton---southampton 0.11126399785280228 \n", "1628899200---everton---southampton 0.08816669881343842 \n", "1628899200---everton---southampton 0.09325270354747772 \n", "1628899200---everton---southampton 0.01725040003657341 \n", "\n", " player h_a ... \\\n", "id ... \n", "1628899200---everton---southampton Allan h ... \n", "1628899200---everton---southampton Dominic Calvert-Lewin h ... \n", "1628899200---everton---southampton Lucas Digne h ... \n", "1628899200---everton---southampton Dominic Calvert-Lewin h ... \n", "1628899200---everton---southampton Lucas Digne h ... \n", "\n", " situation shot_type match_id \\\n", "id \n", "1628899200---everton---southampton OpenPlay RightFoot 16380 \n", "1628899200---everton---southampton OpenPlay Head 16380 \n", "1628899200---everton---southampton DirectFreekick LeftFoot 16380 \n", "1628899200---everton---southampton OpenPlay Head 16380 \n", "1628899200---everton---southampton FromCorner LeftFoot 16380 \n", "\n", " team_home team_away goals_home \\\n", "id \n", "1628899200---everton---southampton Everton Southampton 3 \n", "1628899200---everton---southampton Everton Southampton 3 \n", "1628899200---everton---southampton Everton Southampton 3 \n", "1628899200---everton---southampton Everton Southampton 3 \n", "1628899200---everton---southampton Everton Southampton 3 \n", "\n", " goals_away date player_assisted \\\n", "id \n", "1628899200---everton---southampton 1 2021-08-14 None \n", "1628899200---everton---southampton 1 2021-08-14 Demarai Gray \n", "1628899200---everton---southampton 1 2021-08-14 None \n", "1628899200---everton---southampton 1 2021-08-14 Andros Townsend \n", "1628899200---everton---southampton 1 2021-08-14 None \n", "\n", " last_action \n", "id \n", "1628899200---everton---southampton None \n", "1628899200---everton---southampton Aerial \n", "1628899200---everton---southampton Standard \n", "1628899200---everton---southampton Cross \n", "1628899200---everton---southampton None \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "shots = under.get_shots(\"16380\")\n", "shots.head()" ] }, { "cell_type": "markdown", "id": "f798684e-baef-4a1a-9434-795623056a16", "metadata": {}, "source": [ "## Get the other stats for the fixture" ] }, { "cell_type": "code", "execution_count": 5, "id": "f20ba7af-78f6-4a6a-a18b-eace50eac2ec", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>competition</th>\n", " <th>season</th>\n", " <th>datetime</th>\n", " <th>fid</th>\n", " <th>h</th>\n", " <th>a</th>\n", " <th>date</th>\n", " <th>league_id</th>\n", " <th>goals_home</th>\n", " <th>goals_away</th>\n", " <th>...</th>\n", " <th>h_l</th>\n", " <th>league</th>\n", " <th>shots_home</th>\n", " <th>shots_away</th>\n", " <th>shots_on_target_home</th>\n", " <th>shots_on_target_away</th>\n", " <th>deep_home</th>\n", " <th>deep_away</th>\n", " <th>ppda_away</th>\n", " <th>ppda_home</th>\n", " </tr>\n", " <tr>\n", " <th>id</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>1628899200---everton---southampton</th>\n", " <td>ENG Premier League</td>\n", " <td>2021-2022</td>\n", " <td>2021-08-14 14:00:00</td>\n", " <td>1549542</td>\n", " <td>72</td>\n", " <td>74</td>\n", " <td>2021-08-14</td>\n", " <td>1</td>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>...</td>\n", " <td>0.0407</td>\n", " <td>EPL</td>\n", " <td>14</td>\n", " <td>6</td>\n", " <td>6</td>\n", " <td>3</td>\n", " <td>4</td>\n", " <td>6</td>\n", " <td>5.5926</td>\n", " <td>6.8696</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>1 rows أ— 26 columns</p>\n", "</div>" ], "text/plain": [ " competition season \\\n", "id \n", "1628899200---everton---southampton ENG Premier League 2021-2022 \n", "\n", " datetime fid h a \\\n", "id \n", "1628899200---everton---southampton 2021-08-14 14:00:00 1549542 72 74 \n", "\n", " date league_id goals_home \\\n", "id \n", "1628899200---everton---southampton 2021-08-14 1 3 \n", "\n", " goals_away ... h_l league shots_home \\\n", "id ... \n", "1628899200---everton---southampton 1 ... 0.0407 EPL 14 \n", "\n", " shots_away shots_on_target_home \\\n", "id \n", "1628899200---everton---southampton 6 6 \n", "\n", " shots_on_target_away deep_home deep_away \\\n", "id \n", "1628899200---everton---southampton 3 4 6 \n", "\n", " ppda_away ppda_home \n", "id \n", "1628899200---everton---southampton 5.5926 6.8696 \n", "\n", "[1 rows x 26 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "info = under.get_fixture_info(\"16380\")\n", "\n", "info" ] }, { "cell_type": "markdown", "id": "404041e7-071e-4032-a2e3-bc1f2306d8a3", "metadata": {}, "source": [ "## Get the season for Erling Haaland" ] }, { "cell_type": "code", "execution_count": 6, "id": "cd39ac9b-f7a1-45f2-813a-fcb71186cdbc", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>team</th>\n", " <th>position</th>\n", " <th>games</th>\n", " <th>goals</th>\n", " <th>shots</th>\n", " <th>time</th>\n", " <th>x_g</th>\n", " <th>assists</th>\n", " <th>x_a</th>\n", " <th>key_passes</th>\n", " <th>yellow</th>\n", " <th>red</th>\n", " <th>npg</th>\n", " <th>npx_g</th>\n", " <th>x_g_chain</th>\n", " <th>x_g_buildup</th>\n", " </tr>\n", " <tr>\n", " <th>season</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>2019</th>\n", " <td>Borussia Dortmund</td>\n", " <td>Sub</td>\n", " <td>15</td>\n", " <td>13</td>\n", " <td>33</td>\n", " <td>1061</td>\n", " <td>8.889357395470142</td>\n", " <td>2</td>\n", " <td>1.5264755114912987</td>\n", " <td>9</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>13</td>\n", " <td>8.889357395470142</td>\n", " <td>11.366187927313149</td>\n", " <td>2.984985080547631</td>\n", " </tr>\n", " <tr>\n", " <th>2020</th>\n", " <td>Borussia Dortmund</td>\n", " <td>FW</td>\n", " <td>28</td>\n", " <td>27</td>\n", " <td>92</td>\n", " <td>2416</td>\n", " <td>23.59848389774561</td>\n", " <td>6</td>\n", " <td>4.03544756770134</td>\n", " <td>27</td>\n", " <td>2</td>\n", " <td>0</td>\n", " <td>25</td>\n", " <td>20.567368783056736</td>\n", " <td>27.197287127375603</td>\n", " <td>5.896189399063587</td>\n", " </tr>\n", " <tr>\n", " <th>2021</th>\n", " <td>Borussia Dortmund</td>\n", " <td>FW</td>\n", " <td>24</td>\n", " <td>22</td>\n", " <td>80</td>\n", " <td>1917</td>\n", " <td>17.030953601002693</td>\n", " <td>7</td>\n", " <td>5.894002065062523</td>\n", " <td>23</td>\n", " <td>3</td>\n", " <td>0</td>\n", " <td>16</td>\n", " <td>12.484372556209564</td>\n", " <td>19.77244157716632</td>\n", " <td>4.264734441414475</td>\n", " </tr>\n", " <tr>\n", " <th>2022</th>\n", " <td>Manchester City</td>\n", " <td>FW</td>\n", " <td>35</td>\n", " <td>36</td>\n", " <td>123</td>\n", " <td>2803</td>\n", " <td>32.761399537324905</td>\n", " <td>8</td>\n", " <td>5.8491098545491695</td>\n", " <td>29</td>\n", " <td>5</td>\n", " <td>0</td>\n", " <td>29</td>\n", " <td>27.433209866285324</td>\n", " <td>31.963398084044456</td>\n", " <td>3.285816218703985</td>\n", " </tr>\n", " <tr>\n", " <th>2023</th>\n", " <td>Manchester City</td>\n", " <td>FW</td>\n", " <td>31</td>\n", " <td>27</td>\n", " <td>122</td>\n", " <td>2581</td>\n", " <td>31.65399668365717</td>\n", " <td>5</td>\n", " <td>4.7517555598169565</td>\n", " <td>29</td>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>20</td>\n", " <td>25.564646281301975</td>\n", " <td>30.19725350290537</td>\n", " <td>3.128645434975624</td>\n", " </tr>\n", " <tr>\n", " <th>2024</th>\n", " <td>Manchester City</td>\n", " <td>FW</td>\n", " <td>15</td>\n", " <td>13</td>\n", " <td>70</td>\n", " <td>1350</td>\n", " <td>14.533826172351837</td>\n", " <td>1</td>\n", " <td>1.5637084767222404</td>\n", " <td>11</td>\n", " <td>2</td>\n", " <td>0</td>\n", " <td>12</td>\n", " <td>13.772657334804535</td>\n", " <td>12.936081945896149</td>\n", " <td>1.5715587697923183</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " team position games goals shots time \\\n", "season \n", "2019 Borussia Dortmund Sub 15 13 33 1061 \n", "2020 Borussia Dortmund FW 28 27 92 2416 \n", "2021 Borussia Dortmund FW 24 22 80 1917 \n", "2022 Manchester City FW 35 36 123 2803 \n", "2023 Manchester City FW 31 27 122 2581 \n", "2024 Manchester City FW 15 13 70 1350 \n", "\n", " x_g assists x_a key_passes yellow red \\\n", "season \n", "2019 8.889357395470142 2 1.5264755114912987 9 0 0 \n", "2020 23.59848389774561 6 4.03544756770134 27 2 0 \n", "2021 17.030953601002693 7 5.894002065062523 23 3 0 \n", "2022 32.761399537324905 8 5.8491098545491695 29 5 0 \n", "2023 31.65399668365717 5 4.7517555598169565 29 1 0 \n", "2024 14.533826172351837 1 1.5637084767222404 11 2 0 \n", "\n", " npg npx_g x_g_chain x_g_buildup \n", "season \n", "2019 13 8.889357395470142 11.366187927313149 2.984985080547631 \n", "2020 25 20.567368783056736 27.197287127375603 5.896189399063587 \n", "2021 16 12.484372556209564 19.77244157716632 4.264734441414475 \n", "2022 29 27.433209866285324 31.963398084044456 3.285816218703985 \n", "2023 20 25.564646281301975 30.19725350290537 3.128645434975624 \n", "2024 12 13.772657334804535 12.936081945896149 1.5715587697923183 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "player = under.get_player_season(8260)\n", "player" ] }, { "cell_type": "markdown", "id": "6b6fe251-871b-49fb-a558-82878452cc55", "metadata": {}, "source": [ "## Get all Erling Haaland's shots" ] }, { "cell_type": "code", "execution_count": 7, "id": "07c61458-180a-4393-ba32-8c3df67235ea", "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>minute</th>\n", " <th>result</th>\n", " <th>x</th>\n", " <th>y</th>\n", " <th>x_g</th>\n", " <th>player</th>\n", " <th>h_a</th>\n", " <th>understat_player_id</th>\n", " <th>situation</th>\n", " <th>season</th>\n", " <th>...</th>\n", " <th>understat_fixture_id</th>\n", " <th>team_home</th>\n", " <th>team_away</th>\n", " <th>goals_home</th>\n", " <th>goals_away</th>\n", " <th>date</th>\n", " <th>player_assisted</th>\n", " <th>last_action</th>\n", " <th>datetime</th>\n", " <th>id</th>\n", " </tr>\n", " <tr>\n", " <th>understat_shot_id</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>354876</th>\n", " <td>58</td>\n", " <td>Goal</td>\n", " <td>0.8880000305175781</td>\n", " <td>0.6659999847412109</td>\n", " <td>0.07933320105075836</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2019</td>\n", " <td>...</td>\n", " <td>12562</td>\n", " <td>Augsburg</td>\n", " <td>Borussia Dortmund</td>\n", " <td>3</td>\n", " <td>5</td>\n", " <td>2020-01-18</td>\n", " <td>Jadon Sancho</td>\n", " <td>Throughball</td>\n", " <td>2020-01-18 14:30:00</td>\n", " <td>1579305600---augsburg---borussia_dortmund</td>\n", " </tr>\n", " <tr>\n", " <th>354881</th>\n", " <td>69</td>\n", " <td>Goal</td>\n", " <td>0.98</td>\n", " <td>0.48900001525878906</td>\n", " <td>0.9206209778785706</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2019</td>\n", " <td>...</td>\n", " <td>12562</td>\n", " <td>Augsburg</td>\n", " <td>Borussia Dortmund</td>\n", " <td>3</td>\n", " <td>5</td>\n", " <td>2020-01-18</td>\n", " <td>Thorgan Hazard</td>\n", " <td>Pass</td>\n", " <td>2020-01-18 14:30:00</td>\n", " <td>1579305600---augsburg---borussia_dortmund</td>\n", " </tr>\n", " <tr>\n", " <th>354883</th>\n", " <td>78</td>\n", " <td>Goal</td>\n", " <td>0.8830000305175781</td>\n", " <td>0.34700000762939454</td>\n", " <td>0.32283100485801697</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2019</td>\n", " <td>...</td>\n", " <td>12562</td>\n", " <td>Augsburg</td>\n", " <td>Borussia Dortmund</td>\n", " <td>3</td>\n", " <td>5</td>\n", " <td>2020-01-18</td>\n", " <td>Marco Reus</td>\n", " <td>Throughball</td>\n", " <td>2020-01-18 14:30:00</td>\n", " <td>1579305600---augsburg---borussia_dortmund</td>\n", " </tr>\n", " <tr>\n", " <th>355527</th>\n", " <td>65</td>\n", " <td>BlockedShot</td>\n", " <td>0.8859999847412109</td>\n", " <td>0.639000015258789</td>\n", " <td>0.11918099969625473</td>\n", " <td>Erling Haaland</td>\n", " <td>h</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2019</td>\n", " <td>...</td>\n", " <td>12566</td>\n", " <td>Borussia Dortmund</td>\n", " <td>FC Cologne</td>\n", " <td>5</td>\n", " <td>1</td>\n", " <td>2020-01-24</td>\n", " <td>Jadon Sancho</td>\n", " <td>Pass</td>\n", " <td>2020-01-24 19:30:00</td>\n", " <td>1579824000---borussia_dortmund---fc_cologne</td>\n", " </tr>\n", " <tr>\n", " <th>355531</th>\n", " <td>76</td>\n", " <td>Goal</td>\n", " <td>0.955</td>\n", " <td>0.495</td>\n", " <td>0.7466409802436829</td>\n", " <td>Erling Haaland</td>\n", " <td>h</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2019</td>\n", " <td>...</td>\n", " <td>12566</td>\n", " <td>Borussia Dortmund</td>\n", " <td>FC Cologne</td>\n", " <td>5</td>\n", " <td>1</td>\n", " <td>2020-01-24</td>\n", " <td>None</td>\n", " <td>Rebound</td>\n", " <td>2020-01-24 19:30:00</td>\n", " <td>1579824000---borussia_dortmund---fc_cologne</td>\n", " </tr>\n", " <tr>\n", " <th>...</th>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " </tr>\n", " <tr>\n", " <th>605209</th>\n", " <td>5</td>\n", " <td>SavedShot</td>\n", " <td>0.8630000305175781</td>\n", " <td>0.4929999923706055</td>\n", " <td>0.07168060541152954</td>\n", " <td>Erling Haaland</td>\n", " <td>h</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2024</td>\n", " <td>...</td>\n", " <td>26739</td>\n", " <td>Manchester City</td>\n", " <td>Nottingham Forest</td>\n", " <td>3</td>\n", " <td>0</td>\n", " <td>2024-12-04</td>\n", " <td>Kevin De Bruyne</td>\n", " <td>Cross</td>\n", " <td>2024-12-04 19:30:00</td>\n", " <td>1733270400---manchester_city---nottingham_forest</td>\n", " </tr>\n", " <tr>\n", " <th>605236</th>\n", " <td>91</td>\n", " <td>MissedShots</td>\n", " <td>0.8209999847412109</td>\n", " <td>0.700999984741211</td>\n", " <td>0.2730585038661957</td>\n", " <td>Erling Haaland</td>\n", " <td>h</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2024</td>\n", " <td>...</td>\n", " <td>26739</td>\n", " <td>Manchester City</td>\n", " <td>Nottingham Forest</td>\n", " <td>3</td>\n", " <td>0</td>\n", " <td>2024-12-04</td>\n", " <td>None</td>\n", " <td>None</td>\n", " <td>2024-12-04 19:30:00</td>\n", " <td>1733270400---manchester_city---nottingham_forest</td>\n", " </tr>\n", " <tr>\n", " <th>605849</th>\n", " <td>6</td>\n", " <td>SavedShot</td>\n", " <td>0.89</td>\n", " <td>0.5229999923706055</td>\n", " <td>0.43306636810302734</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2024</td>\n", " <td>...</td>\n", " <td>26747</td>\n", " <td>Crystal Palace</td>\n", " <td>Manchester City</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2024-12-07</td>\n", " <td>Kevin De Bruyne</td>\n", " <td>Throughball</td>\n", " <td>2024-12-07 15:00:00</td>\n", " <td>1733529600---crystal_palace---manchester_city</td>\n", " </tr>\n", " <tr>\n", " <th>605857</th>\n", " <td>29</td>\n", " <td>Goal</td>\n", " <td>0.9290000152587891</td>\n", " <td>0.46</td>\n", " <td>0.2861519753932953</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>OpenPlay</td>\n", " <td>2024</td>\n", " <td>...</td>\n", " <td>26747</td>\n", " <td>Crystal Palace</td>\n", " <td>Manchester City</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2024-12-07</td>\n", " <td>Matheus Nunes</td>\n", " <td>Aerial</td>\n", " <td>2024-12-07 15:00:00</td>\n", " <td>1733529600---crystal_palace---manchester_city</td>\n", " </tr>\n", " <tr>\n", " <th>605868</th>\n", " <td>74</td>\n", " <td>BlockedShot</td>\n", " <td>0.965</td>\n", " <td>0.44</td>\n", " <td>0.06939429044723511</td>\n", " <td>Erling Haaland</td>\n", " <td>a</td>\n", " <td>8260</td>\n", " <td>FromCorner</td>\n", " <td>2024</td>\n", " <td>...</td>\n", " <td>26747</td>\n", " <td>Crystal Palace</td>\n", " <td>Manchester City</td>\n", " <td>2</td>\n", " <td>2</td>\n", " <td>2024-12-07</td>\n", " <td>Matheus Nunes</td>\n", " <td>Aerial</td>\n", " <td>2024-12-07 15:00:00</td>\n", " <td>1733529600---crystal_palace---manchester_city</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>520 rows أ— 21 columns</p>\n", "</div>" ], "text/plain": [ " minute result x \\\n", "understat_shot_id \n", "354876 58 Goal 0.8880000305175781 \n", "354881 69 Goal 0.98 \n", "354883 78 Goal 0.8830000305175781 \n", "355527 65 BlockedShot 0.8859999847412109 \n", "355531 76 Goal 0.955 \n", "... ... ... ... \n", "605209 5 SavedShot 0.8630000305175781 \n", "605236 91 MissedShots 0.8209999847412109 \n", "605849 6 SavedShot 0.89 \n", "605857 29 Goal 0.9290000152587891 \n", "605868 74 BlockedShot 0.965 \n", "\n", " y x_g player \\\n", "understat_shot_id \n", "354876 0.6659999847412109 0.07933320105075836 Erling Haaland \n", "354881 0.48900001525878906 0.9206209778785706 Erling Haaland \n", "354883 0.34700000762939454 0.32283100485801697 Erling Haaland \n", "355527 0.639000015258789 0.11918099969625473 Erling Haaland \n", "355531 0.495 0.7466409802436829 Erling Haaland \n", "... ... ... ... \n", "605209 0.4929999923706055 0.07168060541152954 Erling Haaland \n", "605236 0.700999984741211 0.2730585038661957 Erling Haaland \n", "605849 0.5229999923706055 0.43306636810302734 Erling Haaland \n", "605857 0.46 0.2861519753932953 Erling Haaland \n", "605868 0.44 0.06939429044723511 Erling Haaland \n", "\n", " h_a understat_player_id situation season ... \\\n", "understat_shot_id ... \n", "354876 a 8260 OpenPlay 2019 ... \n", "354881 a 8260 OpenPlay 2019 ... \n", "354883 a 8260 OpenPlay 2019 ... \n", "355527 h 8260 OpenPlay 2019 ... \n", "355531 h 8260 OpenPlay 2019 ... \n", "... .. ... ... ... ... \n", "605209 h 8260 OpenPlay 2024 ... \n", "605236 h 8260 OpenPlay 2024 ... \n", "605849 a 8260 OpenPlay 2024 ... \n", "605857 a 8260 OpenPlay 2024 ... \n", "605868 a 8260 FromCorner 2024 ... \n", "\n", " understat_fixture_id team_home team_away \\\n", "understat_shot_id \n", "354876 12562 Augsburg Borussia Dortmund \n", "354881 12562 Augsburg Borussia Dortmund \n", "354883 12562 Augsburg Borussia Dortmund \n", "355527 12566 Borussia Dortmund FC Cologne \n", "355531 12566 Borussia Dortmund FC Cologne \n", "... ... ... ... \n", "605209 26739 Manchester City Nottingham Forest \n", "605236 26739 Manchester City Nottingham Forest \n", "605849 26747 Crystal Palace Manchester City \n", "605857 26747 Crystal Palace Manchester City \n", "605868 26747 Crystal Palace Manchester City \n", "\n", " goals_home goals_away date player_assisted \\\n", "understat_shot_id \n", "354876 3 5 2020-01-18 Jadon Sancho \n", "354881 3 5 2020-01-18 Thorgan Hazard \n", "354883 3 5 2020-01-18 Marco Reus \n", "355527 5 1 2020-01-24 Jadon Sancho \n", "355531 5 1 2020-01-24 None \n", "... ... ... ... ... \n", "605209 3 0 2024-12-04 Kevin De Bruyne \n", "605236 3 0 2024-12-04 None \n", "605849 2 2 2024-12-07 Kevin De Bruyne \n", "605857 2 2 2024-12-07 Matheus Nunes \n", "605868 2 2 2024-12-07 Matheus Nunes \n", "\n", " last_action datetime \\\n", "understat_shot_id \n", "354876 Throughball 2020-01-18 14:30:00 \n", "354881 Pass 2020-01-18 14:30:00 \n", "354883 Throughball 2020-01-18 14:30:00 \n", "355527 Pass 2020-01-24 19:30:00 \n", "355531 Rebound 2020-01-24 19:30:00 \n", "... ... ... \n", "605209 Cross 2024-12-04 19:30:00 \n", "605236 None 2024-12-04 19:30:00 \n", "605849 Throughball 2024-12-07 15:00:00 \n", "605857 Aerial 2024-12-07 15:00:00 \n", "605868 Aerial 2024-12-07 15:00:00 \n", "\n", " id \n", "understat_shot_id \n", "354876 1579305600---augsburg---borussia_dortmund \n", "354881 1579305600---augsburg---borussia_dortmund \n", "354883 1579305600---augsburg---borussia_dortmund \n", "355527 1579824000---borussia_dortmund---fc_cologne \n", "355531 1579824000---borussia_dortmund---fc_cologne \n", "... ... \n", "605209 1733270400---manchester_city---nottingham_forest \n", "605236 1733270400---manchester_city---nottingham_forest \n", "605849 1733529600---crystal_palace---manchester_city \n", "605857 1733529600---crystal_palace---manchester_city \n", "605868 1733529600---crystal_palace---manchester_city \n", "\n", "[520 rows x 21 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "shots = under.get_player_shots(8260)\n", "shots" ] } ], "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.13.0" } }, "nbformat": 4, "nbformat_minor": 5 }