{ "cells": [ { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "#import packages\n", "import pandas as pd\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#read in data from csv this is from a premier league game Southampton vs Bournemouth in 2019\n", "#I scrpaed this data from understat. I would recommend checking out the tutorial on scraping understat on my Youtube channel\n", "#https://www.youtube.com/c/McKayJohns\n", "df = pd.read_csv('xgtutorial.csv')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Unnamed: 0 | \n", "minute | \n", "team | \n", "xG | \n", "player | \n", "result | \n", "
---|---|---|---|---|---|---|
0 | \n", "0 | \n", "1 | \n", "Southampton | \n", "0.105402 | \n", "Nathan Redmond | \n", "BlockedShot | \n", "
1 | \n", "1 | \n", "2 | \n", "Southampton | \n", "0.136320 | \n", "Jan Bednarek | \n", "BlockedShot | \n", "
2 | \n", "2 | \n", "2 | \n", "Southampton | \n", "0.037217 | \n", "Oriol Romeu | \n", "BlockedShot | \n", "
3 | \n", "3 | \n", "2 | \n", "Southampton | \n", "0.021404 | \n", "James Ward-Prowse | \n", "BlockedShot | \n", "
4 | \n", "4 | \n", "3 | \n", "Southampton | \n", "0.066363 | \n", "Pierre-Emile Højbjerg | \n", "BlockedShot | \n", "
5 | \n", "5 | \n", "9 | \n", "Southampton | \n", "0.363826 | \n", "Nathan Redmond | \n", "SavedShot | \n", "
6 | \n", "6 | \n", "11 | \n", "Southampton | \n", "0.354095 | \n", "Shane Long | \n", "Goal | \n", "
7 | \n", "7 | \n", "17 | \n", "Southampton | \n", "0.036274 | \n", "Nathan Redmond | \n", "MissedShots | \n", "
8 | \n", "8 | \n", "21 | \n", "Southampton | \n", "0.076804 | \n", "Danny Ings | \n", "MissedShots | \n", "
9 | \n", "9 | \n", "23 | \n", "Southampton | \n", "0.380378 | \n", "Shane Long | \n", "SavedShot | \n", "
10 | \n", "10 | \n", "23 | \n", "Southampton | \n", "0.608956 | \n", "Shane Long | \n", "ShotOnPost | \n", "
11 | \n", "11 | \n", "47 | \n", "Southampton | \n", "0.027636 | \n", "Ryan Bertrand | \n", "MissedShots | \n", "
12 | \n", "12 | \n", "49 | \n", "Southampton | \n", "0.026454 | \n", "Nathan Redmond | \n", "MissedShots | \n", "
13 | \n", "13 | \n", "54 | \n", "Southampton | \n", "0.033908 | \n", "James Ward-Prowse | \n", "Goal | \n", "
14 | \n", "14 | \n", "57 | \n", "Southampton | \n", "0.429492 | \n", "Danny Ings | \n", "SavedShot | \n", "
15 | \n", "15 | \n", "58 | \n", "Southampton | \n", "0.021995 | \n", "Danny Ings | \n", "SavedShot | \n", "
16 | \n", "16 | \n", "60 | \n", "Southampton | \n", "0.050620 | \n", "Matt Targett | \n", "BlockedShot | \n", "
17 | \n", "17 | \n", "60 | \n", "Southampton | \n", "0.053497 | \n", "Nathan Redmond | \n", "MissedShots | \n", "
18 | \n", "18 | \n", "66 | \n", "Southampton | \n", "0.086690 | \n", "Matt Targett | \n", "Goal | \n", "
19 | \n", "19 | \n", "71 | \n", "Southampton | \n", "0.011735 | \n", "Pierre-Emile Højbjerg | \n", "MissedShots | \n", "
20 | \n", "20 | \n", "79 | \n", "Southampton | \n", "0.023274 | \n", "Nathan Redmond | \n", "MissedShots | \n", "
21 | \n", "21 | \n", "81 | \n", "Southampton | \n", "0.018172 | \n", "Pierre-Emile Højbjerg | \n", "MissedShots | \n", "
22 | \n", "22 | \n", "19 | \n", "Bournemouth | \n", "0.516069 | \n", "Dan Gosling | \n", "Goal | \n", "
23 | \n", "23 | \n", "31 | \n", "Bournemouth | \n", "0.016307 | \n", "David Brooks | \n", "SavedShot | \n", "
24 | \n", "24 | \n", "31 | \n", "Bournemouth | \n", "0.515468 | \n", "Callum Wilson | \n", "Goal | \n", "
25 | \n", "25 | \n", "51 | \n", "Bournemouth | \n", "0.025648 | \n", "Jack Simpson | \n", "MissedShots | \n", "
26 | \n", "26 | \n", "72 | \n", "Bournemouth | \n", "0.034942 | \n", "Ryan Fraser | \n", "MissedShots | \n", "
27 | \n", "27 | \n", "82 | \n", "Bournemouth | \n", "0.017407 | \n", "Joshua King | \n", "MissedShots | \n", "
28 | \n", "28 | \n", "85 | \n", "Bournemouth | \n", "0.973102 | \n", "Callum Wilson | \n", "Goal | \n", "
29 | \n", "29 | \n", "87 | \n", "Bournemouth | \n", "0.506683 | \n", "Callum Wilson | \n", "SavedShot | \n", "
30 | \n", "30 | \n", "94 | \n", "Bournemouth | \n", "0.024924 | \n", "Joshua King | \n", "MissedShots | \n", "