{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Premier League Crosses\n", "\n", "### Imports and Fonts" ] }, { "cell_type": "code", "execution_count": 260, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib.ticker as ticker\n", "import matplotlib.patheffects as path_effects\n", "import matplotlib.font_manager as fm\n", "from matplotlib.patches import RegularPolygon\n", "import matplotlib.patches as mpatches\n", "from matplotlib import cm\n", "import numpy as np\n", "from matplotlib import cm\n", "from highlight_text import fig_text, ax_text\n", "from ast import literal_eval\n", "\n", "from mplsoccer import Pitch, VerticalPitch\n", "\n", "from PIL import Image\n", "import urllib\n", "import os" ] }, { "cell_type": "code", "execution_count": 261, "metadata": {}, "outputs": [], "source": [ "font_path = \"../assets/fonts\"\n", "for x in os.listdir(font_path):\n", " for y in os.listdir(f\"{font_path}/{x}\"):\n", " if (y.split(\".\")[-1] == \"ttf\") or (y.split(\".\")[-1] == \"otf\"):\n", " fm.fontManager.addfont(f\"{font_path}/{x}/{y}\")\n", " try:\n", " fm.FontProperties(weight=y.split(\"-\")[-1].split(\".\")[0].lower(), fname=y.split(\"-\")[0])\n", " except Exception:\n", " continue\n", "\n", "plt.style.use(\"../assets/stylesheets/soc_base.mplstyle\")\n", "plt.rcParams['font.family'] = 'DM Sans'" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Reading and cleaning the data" ] }, { "cell_type": "code", "execution_count": 262, "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv('data/2022_2023_premier_league.csv', index_col=0, low_memory=False)\n", "data['qualifiers'] = [literal_eval(x) for x in data['qualifiers']]\n", "data['satisfied_events_types'] = [literal_eval(x) for x in data['satisfied_events_types']]\n", "team_map = pd.read_csv('data/team_mapping.csv', encoding='utf-8')" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Now we filter only those events related to crosses." ] }, { "cell_type": "code", "execution_count": 263, "metadata": {}, "outputs": [], "source": [ "data_crosses = data.copy()\n", "data_crosses['is_cross'] = False\n", "data['is_assist'] = False\n", "for index, row in enumerate(data_crosses['satisfied_events_types']):\n", " if ('passCrossInaccurate' in row or 'passCrossAccurate' in row) and ('passCorner' not in row):\n", " data_crosses.at[index, 'is_cross'] = True\n", " if 'assist' in row:\n", " data_crosses.at[index, 'is_assist'] = True" ] }, { "cell_type": "code", "execution_count": 264, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | event_id | \n", "minute | \n", "second | \n", "team_id | \n", "x | \n", "y | \n", "expanded_minute | \n", "period | \n", "outcome_type | \n", "qualifiers | \n", "... | \n", "event_type | \n", "pass_recipient | \n", "team_name | \n", "match_date | \n", "match_id | \n", "match_string | \n", "is_own_goal | \n", "is_cross | \n", "is_assist | \n", "fotmob_id | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2.493198e+09 | \n", "6 | \n", "27.0 | \n", "189 | \n", "83.9 | \n", "9.1 | \n", "6 | \n", "FirstHalf | \n", "Unsuccessful | \n", "[{'RightFoot': True}, {'Zone': 'Right'}, {'Cro... | \n", "... | \n", "Pass | \n", "NaN | \n", "Brentford | \n", "2022-12-26T12:30:00 | \n", "1640836 | \n", "Brentford - Tottenham | \n", "NaN | \n", "True | \n", "NaN | \n", "9937 | \n", "
1 | \n", "2.493199e+09 | \n", "9 | \n", "34.0 | \n", "30 | \n", "97.5 | \n", "16.1 | \n", "9 | \n", "FirstHalf | \n", "Unsuccessful | \n", "[{'PassEndX': '89.8'}, {'Cross': True}, {'Leng... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2022-12-26T12:30:00 | \n", "1640836 | \n", "Brentford - Tottenham | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
2 | \n", "2.493200e+09 | \n", "16 | \n", "0.0 | \n", "189 | \n", "90.2 | \n", "87.8 | \n", "16 | \n", "FirstHalf | \n", "Unsuccessful | \n", "[{'Cross': True}, {'Length': '1.8'}, {'PassEnd... | \n", "... | \n", "Pass | \n", "NaN | \n", "Brentford | \n", "2022-12-26T12:30:00 | \n", "1640836 | \n", "Brentford - Tottenham | \n", "NaN | \n", "True | \n", "NaN | \n", "9937 | \n", "
3 | \n", "2.493203e+09 | \n", "27 | \n", "28.0 | \n", "189 | \n", "68.3 | \n", "78.3 | \n", "27 | \n", "FirstHalf | \n", "Unsuccessful | \n", "[{'Length': '31.9'}, {'PassEndX': '92.4'}, {'F... | \n", "... | \n", "Pass | \n", "NaN | \n", "Brentford | \n", "2022-12-26T12:30:00 | \n", "1640836 | \n", "Brentford - Tottenham | \n", "NaN | \n", "True | \n", "NaN | \n", "9937 | \n", "
4 | \n", "2.493204e+09 | \n", "28 | \n", "39.0 | \n", "30 | \n", "96.1 | \n", "83.5 | \n", "28 | \n", "FirstHalf | \n", "Successful | \n", "[{'PassEndY': '26.4'}, {'Angle': '4.7'}, {'Pas... | \n", "... | \n", "Pass | \n", "Matt Doherty | \n", "Tottenham | \n", "2022-12-26T12:30:00 | \n", "1640836 | \n", "Brentford - Tottenham | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
3920 | \n", "2.494468e+09 | \n", "66 | \n", "17.0 | \n", "30 | \n", "88.4 | \n", "10.8 | \n", "69 | \n", "SecondHalf | \n", "Unsuccessful | \n", "[{'Cross': True}, {'OppositeRelatedEvent': '53... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2023-01-01T14:00:00 | \n", "1640851 | \n", "Tottenham - Aston Villa | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
3921 | \n", "2.494472e+09 | \n", "72 | \n", "1.0 | \n", "30 | \n", "78.9 | \n", "90.9 | \n", "75 | \n", "SecondHalf | \n", "Unsuccessful | \n", "[{'OppositeRelatedEvent': '594'}, {'Cross': Tr... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2023-01-01T14:00:00 | \n", "1640851 | \n", "Tottenham - Aston Villa | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
3922 | \n", "2.494477e+09 | \n", "78 | \n", "21.0 | \n", "30 | \n", "90.9 | \n", "18.6 | \n", "81 | \n", "SecondHalf | \n", "Unsuccessful | \n", "[{'PassEndX': '91.6'}, {'Length': '16.3'}, {'A... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2023-01-01T14:00:00 | \n", "1640851 | \n", "Tottenham - Aston Villa | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
3923 | \n", "2.494489e+09 | \n", "92 | \n", "49.0 | \n", "30 | \n", "94.5 | \n", "95.2 | \n", "95 | \n", "SecondHalf | \n", "Unsuccessful | \n", "[{'PassEndX': '93.8'}, {'Length': '24.3'}, {'L... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2023-01-01T14:00:00 | \n", "1640851 | \n", "Tottenham - Aston Villa | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
3924 | \n", "2.494489e+09 | \n", "93 | \n", "1.0 | \n", "30 | \n", "80.6 | \n", "90.4 | \n", "96 | \n", "SecondHalf | \n", "Unsuccessful | \n", "[{'Length': '24.2'}, {'PassEndX': '90.7'}, {'C... | \n", "... | \n", "Pass | \n", "NaN | \n", "Tottenham | \n", "2023-01-01T14:00:00 | \n", "1640851 | \n", "Tottenham - Aston Villa | \n", "NaN | \n", "True | \n", "NaN | \n", "8586 | \n", "
3925 rows × 35 columns
\n", "\n", " | team_name | \n", "fotmob_id | \n", "is_cross | \n", "
---|---|---|---|
0 | \n", "West Ham | \n", "8654 | \n", "267 | \n", "
1 | \n", "Tottenham | \n", "8586 | \n", "265 | \n", "
2 | \n", "Liverpool | \n", "8650 | \n", "245 | \n", "
3 | \n", "Fulham | \n", "9879 | \n", "244 | \n", "
4 | \n", "Man City | \n", "8456 | \n", "223 | \n", "
5 | \n", "Southampton | \n", "8466 | \n", "219 | \n", "
6 | \n", "Wolves | \n", "8602 | \n", "205 | \n", "
7 | \n", "Newcastle | \n", "10261 | \n", "202 | \n", "
8 | \n", "Brentford | \n", "9937 | \n", "198 | \n", "
9 | \n", "Nottingham Forest | \n", "10203 | \n", "196 | \n", "
10 | \n", "Aston Villa | \n", "10252 | \n", "195 | \n", "
11 | \n", "Brighton | \n", "10204 | \n", "193 | \n", "
12 | \n", "Arsenal | \n", "9825 | \n", "182 | \n", "
13 | \n", "Chelsea | \n", "8455 | \n", "178 | \n", "
14 | \n", "Everton | \n", "8668 | \n", "176 | \n", "
15 | \n", "Leeds | \n", "8463 | \n", "167 | \n", "
16 | \n", "Leicester | \n", "8197 | \n", "158 | \n", "
17 | \n", "Bournemouth | \n", "8678 | \n", "147 | \n", "
18 | \n", "Man Utd | \n", "10260 | \n", "143 | \n", "
19 | \n", "Crystal Palace | \n", "9826 | \n", "122 | \n", "