{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quantifying Non-Shot Chances\n", "\n", "This notebook uses the Logistic Regression Expected Goals model trained using StatsBomb event data on Metrica's sample tracking data (match 2) to calculate the expected goals and the non-shot expected goals of the match.\n", "\n", "Starts with loading and preprocessing the Metrica tracking and event data by transforming the coordinates to be cinsistent with StatsBombs.\n", "\n", "Traditional match stats are calculated from the event data.\n", "\n", "Possessions are defined and identified using Metrica's possession definitions with event types 'BALL LOST' and 'BALL OUT'.\n", "\n", "Expected goals and non-shot expected goals are calculated for both Home and Away teams across all frames of the match.\n", "\n", "Expected goals are summed for each shot taken whilst non-shot expected goals include possessions which no shots were attempted. In these possessions, the maximum non-shot expected goal value is taken across the whole possession and attributed to that possession.\n", "\n", "Outcomes are at the bottom. This allows possessions where shots weren't taken to still be accounted for in post match statistics, further analysis such as difference between expected goals and non-shot expected goals can be extrapolated upon and discussed. But having the ability to start the conversation is great.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:28.529699Z", "start_time": "2021-01-03T13:22:27.876894Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "\n", "\n", "import Metrica_IO as mio\n", "import Metrica_Functions_TLMAnalytics as mfun\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "pd.options.display.max_rows = 100\n", "pd.options.display.max_columns = 100" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Metrica Tracking Data\n", "\n", "Loading data using MetricaIO, need to convert to StatsBomb consistent coordinates since xG model was trained using that coordinate system. The coefficients of the Logistic Regressions are dependent on those coordinate distances and angles." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:29.474688Z", "start_time": "2021-01-03T13:22:28.531694Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reading team: home\n", "Reading team: away\n" ] }, { "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", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_y
Frame
110.040.942750.504130.648120.286050.677520.428030.698820.556060.643480.762530.233390.258690.602690.473970.585080.530170.531630.750840.506370.301370.501940.61123NaNNaNNaNNaNNaNNaNNaNNaN
210.080.942750.504130.648120.286050.677520.428030.698820.556060.643480.762530.233390.258690.602690.473970.585080.530170.531630.750840.506370.301370.501940.61123NaNNaNNaNNaNNaNNaNNaNNaN
310.120.942750.504130.648120.286050.677520.428030.698820.556060.643480.762530.233390.258690.602690.473970.585080.530170.531630.750840.506370.301370.501940.61123NaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "Frame \n", "1 1 0.04 0.94275 0.50413 0.64812 0.28605 0.67752 \n", "2 1 0.08 0.94275 0.50413 0.64812 0.28605 0.67752 \n", "3 1 0.12 0.94275 0.50413 0.64812 0.28605 0.67752 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "Frame \n", "1 0.42803 0.69882 0.55606 0.64348 0.76253 0.23339 0.25869 \n", "2 0.42803 0.69882 0.55606 0.64348 0.76253 0.23339 0.25869 \n", "3 0.42803 0.69882 0.55606 0.64348 0.76253 0.23339 0.25869 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "Frame \n", "1 0.60269 0.47397 0.58508 0.53017 0.53163 0.75084 0.50637 \n", "2 0.60269 0.47397 0.58508 0.53017 0.53163 0.75084 0.50637 \n", "3 0.60269 0.47397 0.58508 0.53017 0.53163 0.75084 0.50637 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x \\\n", "Frame \n", "1 0.30137 0.50194 0.61123 NaN NaN NaN \n", "2 0.30137 0.50194 0.61123 NaN NaN NaN \n", "3 0.30137 0.50194 0.61123 NaN NaN NaN \n", "\n", " Home_13_y Home_14_x Home_14_y ball_x ball_y \n", "Frame \n", "1 NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Load in Metrica events and tracking data using Metrica_IO from Friends of Tracking\n", "events = mio.read_event_data('sample-data-master/data',2)\n", "tracking_home = mio.tracking_data('sample-data-master/data'\n", " , 2\n", " , 'Home')\n", "tracking_away = mio.tracking_data('sample-data-master/data/'\n", " , 2\n", " , 'Away')\n", "tracking_home.head(3)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:29.618295Z", "start_time": "2021-01-03T13:22:29.475677Z" } }, "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", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_y
Frame
14115425646.167.54239.005646.198867.715227.069646.91632.570454.2328NaNNaN48.710473.598446.783234.936843.459235.0256NaNNaN33.986451.1464NaNNaN49.004468.440861.23484.231233.637250.6192NaNNaN
14115525646.207.54239.005646.198867.715227.069646.91632.570454.2328NaNNaN48.710473.598446.801235.033643.459235.0256NaNNaN33.919251.1240NaNNaN49.004468.440861.23364.166433.670850.6352NaNNaN
14115625646.247.54239.005646.198867.715227.069646.91632.570454.2328NaNNaN48.710473.598446.808435.000043.459235.0256NaNNaN33.841251.1016NaNNaN49.004468.440861.23484.123233.678050.8072NaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "Frame \n", "141154 2 5646.16 7.542 39.0056 46.1988 67.7152 27.0696 \n", "141155 2 5646.20 7.542 39.0056 46.1988 67.7152 27.0696 \n", "141156 2 5646.24 7.542 39.0056 46.1988 67.7152 27.0696 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "Frame \n", "141154 46.916 32.5704 54.2328 NaN NaN 48.7104 73.5984 \n", "141155 46.916 32.5704 54.2328 NaN NaN 48.7104 73.5984 \n", "141156 46.916 32.5704 54.2328 NaN NaN 48.7104 73.5984 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "Frame \n", "141154 46.7832 34.9368 43.4592 35.0256 NaN NaN 33.9864 \n", "141155 46.8012 35.0336 43.4592 35.0256 NaN NaN 33.9192 \n", "141156 46.8084 35.0000 43.4592 35.0256 NaN NaN 33.8412 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x \\\n", "Frame \n", "141154 51.1464 NaN NaN 49.0044 68.4408 61.2348 \n", "141155 51.1240 NaN NaN 49.0044 68.4408 61.2336 \n", "141156 51.1016 NaN NaN 49.0044 68.4408 61.2348 \n", "\n", " Home_13_y Home_14_x Home_14_y ball_x ball_y \n", "Frame \n", "141154 4.2312 33.6372 50.6192 NaN NaN \n", "141155 4.1664 33.6708 50.6352 NaN NaN \n", "141156 4.1232 33.6780 50.8072 NaN NaN " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Convert Metrica coordinates to StatsBomb coordinates\n", "events = mfun.to_statsbomb_coordinates(events)\n", "tracking_home = mfun.to_statsbomb_coordinates(tracking_home)\n", "tracking_away = mfun.to_statsbomb_coordinates(tracking_away)\n", "tracking_home.tail(3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:29.883586Z", "start_time": "2021-01-03T13:22:29.619293Z" } }, "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", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_y
Frame
14115425646.16112.45840.994473.801212.284892.930433.08487.429625.7672NaNNaN71.28966.401673.216845.063276.540844.9744NaNNaN86.013628.8536NaNNaN70.995611.559258.765275.768886.362829.3808NaNNaN
14115525646.20112.45840.994473.801212.284892.930433.08487.429625.7672NaNNaN71.28966.401673.198844.966476.540844.9744NaNNaN86.080828.8760NaNNaN70.995611.559258.766475.833686.329229.3648NaNNaN
14115625646.24112.45840.994473.801212.284892.930433.08487.429625.7672NaNNaN71.28966.401673.191645.000076.540844.9744NaNNaN86.158828.8984NaNNaN70.995611.559258.765275.876886.322029.1928NaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "Frame \n", "141154 2 5646.16 112.458 40.9944 73.8012 12.2848 92.9304 \n", "141155 2 5646.20 112.458 40.9944 73.8012 12.2848 92.9304 \n", "141156 2 5646.24 112.458 40.9944 73.8012 12.2848 92.9304 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "Frame \n", "141154 33.084 87.4296 25.7672 NaN NaN 71.2896 6.4016 \n", "141155 33.084 87.4296 25.7672 NaN NaN 71.2896 6.4016 \n", "141156 33.084 87.4296 25.7672 NaN NaN 71.2896 6.4016 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "Frame \n", "141154 73.2168 45.0632 76.5408 44.9744 NaN NaN 86.0136 \n", "141155 73.1988 44.9664 76.5408 44.9744 NaN NaN 86.0808 \n", "141156 73.1916 45.0000 76.5408 44.9744 NaN NaN 86.1588 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x \\\n", "Frame \n", "141154 28.8536 NaN NaN 70.9956 11.5592 58.7652 \n", "141155 28.8760 NaN NaN 70.9956 11.5592 58.7664 \n", "141156 28.8984 NaN NaN 70.9956 11.5592 58.7652 \n", "\n", " Home_13_y Home_14_x Home_14_y ball_x ball_y \n", "Frame \n", "141154 75.7688 86.3628 29.3808 NaN NaN \n", "141155 75.8336 86.3292 29.3648 NaN NaN \n", "141156 75.8768 86.3220 29.1928 NaN NaN " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# reverse direction of play in the second half so that home team is always attacking from right->left\n", "tracking_home,tracking_away,events = mfun.to_single_playing_direction(tracking_home,tracking_away,events)\n", "tracking_home.tail(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Match Stats\n", "\n", "Traditional stats such as goals, shots and passes are calculated here." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:29.913506Z", "start_time": "2021-01-03T13:22:29.886579Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 24 shots in total.\n", "There are 13 shots by the Home team.\n", "There are 3 goals by the Home team.\n", "There are 11 shots by the Away team.\n", "There are 2 goals by the Away team.\n", "There are 964 passes in total.\n", "There are 543 passes by the Home team.\n", "There are 421 passes by the Away team.\n" ] } ], "source": [ "shots = events[events['Type'] == 'SHOT']\n", "print('There are {} shots in total.'.format(shots.shape[0]))\n", "home_shots = shots[shots['Team'] == 'Home']\n", "print('There are {} shots by the Home team.'.format(home_shots.shape[0]))\n", "home_goals = home_shots[home_shots['Subtype'].str.contains('GOAL')]\n", "print('There are {} goals by the Home team.'.format(home_goals.shape[0]))\n", "away_shots = shots[shots['Team'] == 'Away']\n", "print('There are {} shots by the Away team.'.format(away_shots.shape[0]))\n", "away_goals = away_shots[away_shots['Subtype'].str.contains('GOAL')]\n", "print('There are {} goals by the Away team.'.format(away_goals.shape[0]))\n", "passes = events[events['Type'] == 'PASS']\n", "print('There are {} passes in total.'.format(passes.shape[0]))\n", "home_passes = passes[passes['Team'] == 'Home']\n", "print('There are {} passes by the Home team.'.format(home_passes.shape[0]))\n", "away_passes = passes[passes['Team'] == 'Away']\n", "print('There are {} passes by the Away team.'.format(away_passes.shape[0]))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define Possessions\n", "\n", "Possessions change everytime a BALL OUT or BALL LOST occurs. Separate for Home / Away." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:30.022806Z", "start_time": "2021-01-03T13:22:29.915501Z" } }, "outputs": [ { "data": { "text/plain": [ "PASS 964\n", "CHALLENGE 311\n", "RECOVERY 248\n", "BALL LOST 233\n", "SET PIECE 80\n", "BALL OUT 49\n", "SHOT 24\n", "FAULT RECEIVED 20\n", "CARD 6\n", "Name: Type, dtype: int64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "events['Type'].value_counts()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Every time the event type is 'BALL LOST' or 'BALL OUT', the possession ends. The count increases to identify a new possession for the next event." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:30.546157Z", "start_time": "2021-01-03T13:22:30.023803Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TeamTypeSubtypePeriodStart FrameStart Time [s]End FrameEnd Time [s]FromToStart XStart YEnd XEnd YPossession
1919HomeCHALLENGEGROUND-FAULT-WON21374295497.161374295497.16Player1NaN82.84.0NaNNaN146.0
1920HomeFAULT RECEIVEDNaN21374295497.161374295497.16Player1NaN82.84.0NaNNaN146.0
1921HomeSET PIECEFREE KICK21382505530.001382505530.00Player3NaNNaNNaNNaNNaN146.0
1922HomeBALL LOSTINTERCEPTION21382505530.001383345533.36Player3NaN80.44.834.842.4146.0
1924HomeCHALLENGEAERIAL-FAULT-WON21383345533.361383345533.36Player7NaN36.040.0NaNNaN147.0
1926HomeSET PIECEFREE KICK21398915595.641398915595.64Player9NaNNaNNaNNaNNaN147.0
1927HomeSHOTON TARGET-SAVED21398915595.641399255597.00Player9NaN36.041.62.441.6147.0
1931HomeCHALLENGEAERIAL-LOST21401805607.201401805607.20Player1NaN82.824.0NaNNaN147.0
1933HomeRECOVERYNaN21402115608.441402115608.44Player12NaN79.225.6NaNNaN147.0
1934HomeBALL OUTCLEARANCE21402655610.601402985611.92Player12NaN80.412.870.8-3.2147.0
\n", "
" ], "text/plain": [ " Team Type Subtype Period Start Frame \\\n", "1919 Home CHALLENGE GROUND-FAULT-WON 2 137429 \n", "1920 Home FAULT RECEIVED NaN 2 137429 \n", "1921 Home SET PIECE FREE KICK 2 138250 \n", "1922 Home BALL LOST INTERCEPTION 2 138250 \n", "1924 Home CHALLENGE AERIAL-FAULT-WON 2 138334 \n", "1926 Home SET PIECE FREE KICK 2 139891 \n", "1927 Home SHOT ON TARGET-SAVED 2 139891 \n", "1931 Home CHALLENGE AERIAL-LOST 2 140180 \n", "1933 Home RECOVERY NaN 2 140211 \n", "1934 Home BALL OUT CLEARANCE 2 140265 \n", "\n", " Start Time [s] End Frame End Time [s] From To Start X \\\n", "1919 5497.16 137429 5497.16 Player1 NaN 82.8 \n", "1920 5497.16 137429 5497.16 Player1 NaN 82.8 \n", "1921 5530.00 138250 5530.00 Player3 NaN NaN \n", "1922 5530.00 138334 5533.36 Player3 NaN 80.4 \n", "1924 5533.36 138334 5533.36 Player7 NaN 36.0 \n", "1926 5595.64 139891 5595.64 Player9 NaN NaN \n", "1927 5595.64 139925 5597.00 Player9 NaN 36.0 \n", "1931 5607.20 140180 5607.20 Player1 NaN 82.8 \n", "1933 5608.44 140211 5608.44 Player12 NaN 79.2 \n", "1934 5610.60 140298 5611.92 Player12 NaN 80.4 \n", "\n", " Start Y End X End Y Possession \n", "1919 4.0 NaN NaN 146.0 \n", "1920 4.0 NaN NaN 146.0 \n", "1921 NaN NaN NaN 146.0 \n", "1922 4.8 34.8 42.4 146.0 \n", "1924 40.0 NaN NaN 147.0 \n", "1926 NaN NaN NaN 147.0 \n", "1927 41.6 2.4 41.6 147.0 \n", "1931 24.0 NaN NaN 147.0 \n", "1933 25.6 NaN NaN 147.0 \n", "1934 12.8 70.8 -3.2 147.0 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home_events = events[events['Team'] == 'Home']\n", "home_events.loc[:, 'Type_shift'] = home_events.loc[:, 'Type'].shift(1)\n", "possession_count = 1\n", "for index, row in home_events.iterrows():\n", " if (home_events.loc[index, 'Type_shift'] == 'BALL LOST') | (home_events.loc[index, 'Type_shift'] == 'BALL OUT'):\n", " possession_count += 1\n", " home_events.loc[index, 'Possession'] = possession_count\n", " else:\n", " home_events.loc[index, 'Possession'] = possession_count\n", " possession_count = possession_count\n", "home_events.drop(['Type_shift'], axis=1, inplace=True)\n", "home_events.tail(10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Useful to record the frames which each possession starts and ends to merge onto tracking data later on." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:30.560093Z", "start_time": "2021-01-03T13:22:30.547126Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 147 possessions for the Home team.\n" ] }, { "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", "
PossessionStart FrameEnd Frame
01.0504534
12.010841121
23.014311611
34.016721724
45.018741918
\n", "
" ], "text/plain": [ " Possession Start Frame End Frame\n", "0 1.0 504 534\n", "1 2.0 1084 1121\n", "2 3.0 1431 1611\n", "3 4.0 1672 1724\n", "4 5.0 1874 1918" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home_possession_frames = home_events.groupby(['Possession']).agg({'Start Frame': 'min', 'End Frame':'max'}).reset_index()\n", "print('There are {} possessions for the Home team.'.format(home_possession_frames.shape[0]))\n", "home_possession_frames.head(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Repeat for Away team." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:22:31.028466Z", "start_time": "2021-01-03T13:22:30.562088Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are 136 possessions for the Away team.\n" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TeamTypeSubtypePeriodStart FrameStart Time [s]End FrameEnd Time [s]FromToStart XStart YEnd XEnd YPossession
1902AwayCHALLENGEAERIAL-WON21360605442.401360605442.40Player 26NaN114.036.8NaNNaN135.0
1903AwaySHOTHEAD-OFF TARGET-OUT21360605442.401360785443.12Player 26NaN114.036.8123.632.8135.0
1909AwayCHALLENGEGROUND-LOST21370265481.041370265481.04Player21NaN55.261.6NaNNaN135.0
1918AwayCHALLENGEGROUND-FAULT-LOST21374165496.641374165496.64Player20NaN81.65.6NaNNaN135.0
1923AwayCHALLENGEAERIAL-FAULT-LOST21383275533.081383275533.08Player17NaN34.838.4NaNNaN135.0
1925AwayCARDYELLOW21384455537.801384455537.80Player17NaNNaNNaNNaNNaN135.0
1928AwayRECOVERYSAVED21399265597.041399265597.04Player25NaN1.241.6NaNNaN135.0
1929AwayPASSNaN21400105600.401400585602.32Player25Player2115.640.043.264.0135.0
1930AwayBALL LOSTINTERCEPTION21401225604.881401835607.32Player21NaN55.261.685.219.2135.0
1932AwayCHALLENGEAERIAL-LOST21401835607.321401835607.32Player24NaN81.624.0NaNNaN136.0
\n", "
" ], "text/plain": [ " Team Type Subtype Period Start Frame \\\n", "1902 Away CHALLENGE AERIAL-WON 2 136060 \n", "1903 Away SHOT HEAD-OFF TARGET-OUT 2 136060 \n", "1909 Away CHALLENGE GROUND-LOST 2 137026 \n", "1918 Away CHALLENGE GROUND-FAULT-LOST 2 137416 \n", "1923 Away CHALLENGE AERIAL-FAULT-LOST 2 138327 \n", "1925 Away CARD YELLOW 2 138445 \n", "1928 Away RECOVERY SAVED 2 139926 \n", "1929 Away PASS NaN 2 140010 \n", "1930 Away BALL LOST INTERCEPTION 2 140122 \n", "1932 Away CHALLENGE AERIAL-LOST 2 140183 \n", "\n", " Start Time [s] End Frame End Time [s] From To Start X \\\n", "1902 5442.40 136060 5442.40 Player 26 NaN 114.0 \n", "1903 5442.40 136078 5443.12 Player 26 NaN 114.0 \n", "1909 5481.04 137026 5481.04 Player21 NaN 55.2 \n", "1918 5496.64 137416 5496.64 Player20 NaN 81.6 \n", "1923 5533.08 138327 5533.08 Player17 NaN 34.8 \n", "1925 5537.80 138445 5537.80 Player17 NaN NaN \n", "1928 5597.04 139926 5597.04 Player25 NaN 1.2 \n", "1929 5600.40 140058 5602.32 Player25 Player21 15.6 \n", "1930 5604.88 140183 5607.32 Player21 NaN 55.2 \n", "1932 5607.32 140183 5607.32 Player24 NaN 81.6 \n", "\n", " Start Y End X End Y Possession \n", "1902 36.8 NaN NaN 135.0 \n", "1903 36.8 123.6 32.8 135.0 \n", "1909 61.6 NaN NaN 135.0 \n", "1918 5.6 NaN NaN 135.0 \n", "1923 38.4 NaN NaN 135.0 \n", "1925 NaN NaN NaN 135.0 \n", "1928 41.6 NaN NaN 135.0 \n", "1929 40.0 43.2 64.0 135.0 \n", "1930 61.6 85.2 19.2 135.0 \n", "1932 24.0 NaN NaN 136.0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "away_events = events[events['Team'] == 'Away']\n", "away_events.loc[:, 'Type_shift'] = away_events.loc[:, 'Type'].shift(1)\n", "possession_count = 1\n", "for index, row in away_events.iterrows():\n", " if (away_events.loc[index, 'Type_shift'] == 'BALL LOST') | (away_events.loc[index, 'Type_shift'] == 'BALL OUT'):\n", " possession_count += 1\n", " away_events.loc[index, 'Possession'] = possession_count\n", " else:\n", " away_events.loc[index, 'Possession'] = possession_count\n", " possession_count = possession_count\n", "away_events.drop(['Type_shift'], axis=1, inplace=True)\n", "away_possession_frames = away_events.groupby(['Possession']).agg({'Start Frame': 'min', 'End Frame':'max'}).reset_index()\n", "print('There are {} possessions for the Away team.'.format(away_possession_frames.shape[0]))\n", "away_events.tail(10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate xG for all Frames\n", "\n", "For each frame in the tracking data, create features for calculating the xG for each frame according to each specified attacking team.\n", "\n", "Eg. for Home team, the distance calculated will be the distance to the opponents (playing_direction = left to right). And opposite for the Away team.\n", "\n", "### Home" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T13:50:10.067870Z", "start_time": "2021-01-03T13:22:31.029463Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xG
010.04113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
110.08113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
210.12113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
310.16113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.904859.304072.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.403214.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
410.20113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.804059.303272.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.339614.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "0 1 0.04 113.13 39.6696 77.7744 57.116 81.3024 \n", "1 1 0.08 113.13 39.6696 77.7744 57.116 81.3024 \n", "2 1 0.12 113.13 39.6696 77.7744 57.116 81.3024 \n", "3 1 0.16 113.13 39.6696 77.7744 57.116 81.3024 \n", "4 1 0.20 113.13 39.6696 77.7744 57.116 81.3024 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "0 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "1 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "2 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "3 45.7576 83.8584 35.5152 77.2176 18.9976 27.9048 59.3040 \n", "4 45.7576 83.8584 35.5152 77.2176 18.9976 27.8040 59.3032 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "0 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "1 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "2 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "3 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "4 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x Home_13_y \\\n", "0 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "1 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "2 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "3 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "4 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "\n", " Home_14_x Home_14_y ball_x ball_y Away_25_x Away_25_y Away_15_x \\\n", "0 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "1 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "2 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "3 NaN NaN NaN NaN 1.4616 38.5896 39.4032 \n", "4 NaN NaN NaN NaN 1.4616 38.5896 39.3396 \n", "\n", " Away_15_y Away_16_x Away_16_y Away_17_x Away_17_y Away_18_x \\\n", "0 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "1 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "2 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "3 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "4 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "\n", " Away_18_y Away_19_x Away_19_y Away_20_x Away_20_y Away_21_x \\\n", "0 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "1 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "2 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "3 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "4 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "\n", " Away_21_y Away_22_x Away_22_y Away_23_x Away_23_y Away_24_x \\\n", "0 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "1 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "2 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "3 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "4 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "\n", " Away_24_y Away_26_x Away_26_y distance angle \\\n", "0 51.0128 NaN NaN NaN NaN \n", "1 51.0128 NaN NaN NaN NaN \n", "2 51.0128 NaN NaN NaN NaN \n", "3 51.0128 NaN NaN NaN NaN \n", "4 51.0128 NaN NaN NaN NaN \n", "\n", " distance_nearest_defender number_blocking_defenders xG \\\n", "0 NaN 0.0 NaN \n", "1 NaN 0.0 NaN \n", "2 NaN 0.0 NaN \n", "3 NaN 0.0 NaN \n", "4 NaN 0.0 NaN \n", "\n", " distance_nearest_attacker non_shot_xG \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create distance, angle and defender features\n", "home_tracking_frames = mfun.create_features(tracking_home = tracking_home,\n", " tracking_away = tracking_away,\n", " start_frame = 0,\n", " number_frames = tracking_home.shape[0],\n", " field_dimen = (120, 80),\n", " attacking_team = 'Home')\n", "# Calculate xG using logistic regression model\n", "home_tracking_frames = mfun.create_xG(home_tracking_frames)\n", "# Calculate non-shot xG based on if the attacking team is near the ball\n", "home_tracking_frames = mfun.create_non_shot_xG(home_tracking_frames, attacking_team = 'Home')\n", "home_tracking_frames.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Away" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T14:19:08.138681Z", "start_time": "2021-01-03T13:50:10.068838Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xG
010.04113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
110.08113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
210.12113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
310.16113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.904859.304072.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.403214.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
410.20113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.804059.303272.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.339614.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "0 1 0.04 113.13 39.6696 77.7744 57.116 81.3024 \n", "1 1 0.08 113.13 39.6696 77.7744 57.116 81.3024 \n", "2 1 0.12 113.13 39.6696 77.7744 57.116 81.3024 \n", "3 1 0.16 113.13 39.6696 77.7744 57.116 81.3024 \n", "4 1 0.20 113.13 39.6696 77.7744 57.116 81.3024 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "0 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "1 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "2 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "3 45.7576 83.8584 35.5152 77.2176 18.9976 27.9048 59.3040 \n", "4 45.7576 83.8584 35.5152 77.2176 18.9976 27.8040 59.3032 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "0 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "1 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "2 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "3 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "4 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x Home_13_y \\\n", "0 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "1 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "2 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "3 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "4 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "\n", " Home_14_x Home_14_y ball_x ball_y Away_25_x Away_25_y Away_15_x \\\n", "0 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "1 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "2 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "3 NaN NaN NaN NaN 1.4616 38.5896 39.4032 \n", "4 NaN NaN NaN NaN 1.4616 38.5896 39.3396 \n", "\n", " Away_15_y Away_16_x Away_16_y Away_17_x Away_17_y Away_18_x \\\n", "0 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "1 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "2 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "3 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "4 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "\n", " Away_18_y Away_19_x Away_19_y Away_20_x Away_20_y Away_21_x \\\n", "0 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "1 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "2 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "3 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "4 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "\n", " Away_21_y Away_22_x Away_22_y Away_23_x Away_23_y Away_24_x \\\n", "0 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "1 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "2 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "3 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "4 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "\n", " Away_24_y Away_26_x Away_26_y distance angle \\\n", "0 51.0128 NaN NaN NaN NaN \n", "1 51.0128 NaN NaN NaN NaN \n", "2 51.0128 NaN NaN NaN NaN \n", "3 51.0128 NaN NaN NaN NaN \n", "4 51.0128 NaN NaN NaN NaN \n", "\n", " distance_nearest_defender number_blocking_defenders xG \\\n", "0 NaN 0.0 NaN \n", "1 NaN 0.0 NaN \n", "2 NaN 0.0 NaN \n", "3 NaN 0.0 NaN \n", "4 NaN 0.0 NaN \n", "\n", " distance_nearest_attacker non_shot_xG \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create distance, angle and defender features\n", "away_tracking_frames = mfun.create_features(tracking_home = tracking_home,\n", " tracking_away = tracking_away,\n", " start_frame = 0,\n", " number_frames = tracking_home.shape[0],\n", " field_dimen = (120, 80),\n", " attacking_team = 'Away',\n", " playing_direction = 'left-right')\n", "# Calculate xG using logistic regression model\n", "away_tracking_frames = mfun.create_xG(away_tracking_frames)\n", "# Calculate non-shot xG based on if the attacking team is near the ball\n", "away_tracking_frames = mfun.create_non_shot_xG(away_tracking_frames, attacking_team = 'Away')\n", "away_tracking_frames.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Merge on Possession Indentifier by Frames\n", "\n", "Respective Home / Away Possession columns identify the frames which that possession cover. So if Home Possession == 1 for a row, then it's the first possession for the Home team. Similar for Away team.\n", "\n", "This is to ensure we only include the xG values for frames where the team has possession of the ball. We can also use the possessions to find the highest xG_available to the team during that possession.\n", "\n", "### Home" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T14:45:25.731649Z", "start_time": "2021-01-03T14:19:08.140677Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xGHome Possession
010.04113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
110.08113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
210.12113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
310.16113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.904859.304072.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.403214.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
410.20113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.804059.303272.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.339614.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "0 1 0.04 113.13 39.6696 77.7744 57.116 81.3024 \n", "1 1 0.08 113.13 39.6696 77.7744 57.116 81.3024 \n", "2 1 0.12 113.13 39.6696 77.7744 57.116 81.3024 \n", "3 1 0.16 113.13 39.6696 77.7744 57.116 81.3024 \n", "4 1 0.20 113.13 39.6696 77.7744 57.116 81.3024 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "0 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "1 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "2 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "3 45.7576 83.8584 35.5152 77.2176 18.9976 27.9048 59.3040 \n", "4 45.7576 83.8584 35.5152 77.2176 18.9976 27.8040 59.3032 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "0 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "1 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "2 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "3 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "4 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x Home_13_y \\\n", "0 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "1 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "2 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "3 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "4 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "\n", " Home_14_x Home_14_y ball_x ball_y Away_25_x Away_25_y Away_15_x \\\n", "0 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "1 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "2 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "3 NaN NaN NaN NaN 1.4616 38.5896 39.4032 \n", "4 NaN NaN NaN NaN 1.4616 38.5896 39.3396 \n", "\n", " Away_15_y Away_16_x Away_16_y Away_17_x Away_17_y Away_18_x \\\n", "0 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "1 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "2 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "3 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "4 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "\n", " Away_18_y Away_19_x Away_19_y Away_20_x Away_20_y Away_21_x \\\n", "0 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "1 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "2 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "3 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "4 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "\n", " Away_21_y Away_22_x Away_22_y Away_23_x Away_23_y Away_24_x \\\n", "0 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "1 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "2 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "3 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "4 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "\n", " Away_24_y Away_26_x Away_26_y distance angle \\\n", "0 51.0128 NaN NaN NaN NaN \n", "1 51.0128 NaN NaN NaN NaN \n", "2 51.0128 NaN NaN NaN NaN \n", "3 51.0128 NaN NaN NaN NaN \n", "4 51.0128 NaN NaN NaN NaN \n", "\n", " distance_nearest_defender number_blocking_defenders xG \\\n", "0 NaN 0.0 NaN \n", "1 NaN 0.0 NaN \n", "2 NaN 0.0 NaN \n", "3 NaN 0.0 NaN \n", "4 NaN 0.0 NaN \n", "\n", " distance_nearest_attacker non_shot_xG Home Possession \n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 NaN NaN NaN \n", "4 NaN NaN NaN " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Map the Possession identifiers to the respective tracking frames\n", "for index1, row1 in home_tracking_frames.iterrows():\n", " for index2, row2 in home_possession_frames.iterrows():\n", " if (index1 > home_possession_frames.loc[index2, 'Start Frame']) & (index1 < home_possession_frames.loc[index2, 'End Frame']):\n", " home_tracking_frames.loc[index1, 'Home Possession'] = home_possession_frames.loc[index2, 'Possession']\n", " next\n", "home_tracking_frames.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Away" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:10:50.199615Z", "start_time": "2021-01-03T14:45:25.732624Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xGAway Possession
010.04113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
110.08113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
210.12113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997628.006859.304872.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.469214.523236.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
310.16113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.904859.304072.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.403214.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
410.20113.1339.669677.774457.11681.302445.757683.858435.515277.217618.997627.804059.303272.322842.082470.209637.586463.795619.932860.764455.890460.232831.1016NaNNaNNaNNaNNaNNaNNaNNaN1.461638.589639.339614.522436.880835.854438.68248.836843.80655.160859.47686.908847.774442.225651.975654.916859.866881.810460.212439.88459.420451.0128NaNNaNNaNNaNNaN0.0NaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "0 1 0.04 113.13 39.6696 77.7744 57.116 81.3024 \n", "1 1 0.08 113.13 39.6696 77.7744 57.116 81.3024 \n", "2 1 0.12 113.13 39.6696 77.7744 57.116 81.3024 \n", "3 1 0.16 113.13 39.6696 77.7744 57.116 81.3024 \n", "4 1 0.20 113.13 39.6696 77.7744 57.116 81.3024 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "0 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "1 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "2 45.7576 83.8584 35.5152 77.2176 18.9976 28.0068 59.3048 \n", "3 45.7576 83.8584 35.5152 77.2176 18.9976 27.9048 59.3040 \n", "4 45.7576 83.8584 35.5152 77.2176 18.9976 27.8040 59.3032 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "0 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "1 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "2 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "3 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "4 72.3228 42.0824 70.2096 37.5864 63.7956 19.9328 60.7644 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x Home_13_y \\\n", "0 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "1 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "2 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "3 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "4 55.8904 60.2328 31.1016 NaN NaN NaN NaN \n", "\n", " Home_14_x Home_14_y ball_x ball_y Away_25_x Away_25_y Away_15_x \\\n", "0 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "1 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "2 NaN NaN NaN NaN 1.4616 38.5896 39.4692 \n", "3 NaN NaN NaN NaN 1.4616 38.5896 39.4032 \n", "4 NaN NaN NaN NaN 1.4616 38.5896 39.3396 \n", "\n", " Away_15_y Away_16_x Away_16_y Away_17_x Away_17_y Away_18_x \\\n", "0 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "1 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "2 14.5232 36.8808 35.8544 38.682 48.8368 43.806 \n", "3 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "4 14.5224 36.8808 35.8544 38.682 48.8368 43.806 \n", "\n", " Away_18_y Away_19_x Away_19_y Away_20_x Away_20_y Away_21_x \\\n", "0 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "1 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "2 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "3 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "4 55.1608 59.4768 6.9088 47.7744 42.2256 51.9756 \n", "\n", " Away_21_y Away_22_x Away_22_y Away_23_x Away_23_y Away_24_x \\\n", "0 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "1 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "2 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "3 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "4 54.9168 59.8668 81.8104 60.2124 39.884 59.4204 \n", "\n", " Away_24_y Away_26_x Away_26_y distance angle \\\n", "0 51.0128 NaN NaN NaN NaN \n", "1 51.0128 NaN NaN NaN NaN \n", "2 51.0128 NaN NaN NaN NaN \n", "3 51.0128 NaN NaN NaN NaN \n", "4 51.0128 NaN NaN NaN NaN \n", "\n", " distance_nearest_defender number_blocking_defenders xG \\\n", "0 NaN 0.0 NaN \n", "1 NaN 0.0 NaN \n", "2 NaN 0.0 NaN \n", "3 NaN 0.0 NaN \n", "4 NaN 0.0 NaN \n", "\n", " distance_nearest_attacker non_shot_xG Away Possession \n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 NaN NaN NaN \n", "4 NaN NaN NaN " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Map the Possession identifiers to the respective tracking frames\n", "for index1, row1 in away_tracking_frames.iterrows():\n", " for index2, row2 in away_possession_frames.iterrows():\n", " if (index1 > away_possession_frames.loc[index2, 'Start Frame']) & (index1 < away_possession_frames.loc[index2, 'End Frame']):\n", " away_tracking_frames.loc[index1, 'Away Possession'] = away_possession_frames.loc[index2, 'Possession']\n", " next\n", "away_tracking_frames.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Include a Shot Indicator\n", "\n", "The shot indicator will allow the tracking data to know when an actual shot took place. For possessions where shots took place, the xG of the shot can be used to override and other non_shot_xG since the shot takes priority." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:10:50.575616Z", "start_time": "2021-01-03T15:10:50.200634Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xGHome PossessionShot Indicator
44181176.7689.234443.143212.735672.426441.010058.897648.458440.980829.910031.909615.578461.780828.969245.897610.868440.083215.073237.12165.124061.56966.800441.7656NaNNaNNaNNaNNaNNaN15.271261.75681.239643.27526.750035.98245.923241.42725.389249.67446.865260.681611.593238.65449.892853.608811.078444.478418.128460.655237.496457.232832.200835.1632NaNNaN26.5813450.1597823.0622072.00.0191340.3081360.0191347.01.0
122011488.0889.434842.113614.887260.005638.838058.701652.348839.199228.760428.30648.079648.078437.390844.53048.068848.14809.956437.842416.406417.36006.309635.6648NaNNaNNaNNaNNaNNaN6.558036.51602.331640.31928.350833.78966.598835.72326.428446.468810.917657.961613.480834.948812.993648.703215.096040.715219.174851.624838.515258.708828.084829.6264NaNNaN7.4260100.8544380.7938491.00.3307270.8867040.33072716.01.0
164831659.36101.131241.640066.640861.245665.733647.391274.864434.256075.718826.389627.566456.917658.053645.803262.241639.918455.230027.858417.588439.039212.946853.2672NaNNaNNaNNaNNaNNaN13.009253.29044.167642.844014.730037.983211.232043.672811.498451.488036.669658.958463.966031.269620.406046.393635.592038.323273.206064.712077.634044.104075.408055.1432NaNNaN18.5976880.2787612.3518422.00.0487400.0665730.04874021.01.0
2734411093.8087.182441.735218.166864.435239.331250.325610.204832.729657.220841.794444.140834.989617.128839.99928.998830.414414.938817.100826.091667.11608.337638.5528NaNNaNNaNNaNNaNNaN10.387233.14243.822038.014424.430860.76089.925234.12168.018439.230413.254051.604814.818840.555218.624058.100812.864043.280028.341641.120021.626444.748811.073629.7216NaNNaN12.4467100.4926771.0827171.00.1425810.4513020.14258133.01.0
2975311190.1692.126438.953619.350054.701649.629651.992855.603236.820024.532823.660015.051638.261642.560436.030413.928428.500012.592814.642428.035631.772010.107641.2696NaNNaNNaNNaNNaNNaN24.616823.64963.054037.410412.638419.991213.548029.237612.076838.386411.814041.376818.038422.640020.901636.933618.802827.264022.466454.202447.014854.072048.450038.4328NaNNaN29.5520290.2064226.6554221.00.0319720.0846410.03197235.01.0
5607812243.1686.881244.141613.669268.604042.477652.817650.628039.878434.015233.724812.590447.060835.816447.908012.417631.712820.892056.457628.392065.902411.329237.6912NaNNaNNaNNaNNaNNaN12.668447.74162.193641.46969.742833.07929.637238.37608.312445.501611.724063.528815.812432.607218.216044.230414.094053.220820.818860.280040.167634.550430.380453.3064NaNNaN14.8465730.4208554.8981971.00.1551170.6852540.15511765.01.0
6706612682.6891.753239.069623.924460.118453.922048.905653.637626.222432.938825.324023.720424.277642.242444.408815.658818.579220.319643.026414.076037.36489.553236.5432NaNNaNNaNNaNNaNNaN15.679218.48884.010436.131213.989620.27609.336033.561610.308038.51289.693645.127214.625623.342418.337229.784817.786437.284820.677250.434450.541626.285623.352032.2592NaNNaN26.6189600.1635132.4594371.00.0245090.0926730.02450979.01.0
7398222959.3291.382439.224029.451651.574455.954848.095262.187631.589655.918826.21444.749630.331233.249639.591232.175627.87207.221616.02806.356441.213617.864437.2440NaNNaNNaNNaNNaNNaN6.370840.85682.744441.35764.237222.43524.882831.66243.772837.21686.771643.074414.758828.056811.032831.051210.052437.108823.101247.528854.430851.053656.150427.5168NaNNaN6.4281571.0306772.2535281.00.4670640.3570900.46706489.01.0
9887923955.2086.301638.537651.993634.627242.870039.06889.625244.9400NaNNaN32.361619.289614.304035.418433.321625.512815.022820.95045.380815.23844.464034.956023.904044.0848NaNNaNNaNNaN4.615233.99281.807236.41206.354030.74488.353240.77126.169238.43687.988445.290413.184433.259216.202447.73129.880839.5720NaNNaN21.328829.536836.188414.32806.134417.99367.5753890.6543873.6841461.00.3352980.9749950.335298112.01.0
11721724688.7293.687640.184015.831675.289649.101659.050453.830842.0976NaNNaN13.696841.535232.884851.243240.648830.0432NaNNaN12.609648.711210.220437.964016.898461.409624.981668.9048NaNNaN12.836450.43602.188840.776810.140038.424810.135238.48169.463247.545612.468069.982412.900064.487219.190448.038417.641256.5608NaNNaN48.998458.960835.818846.945620.960437.514416.5433750.3462054.4421721.00.1135311.739647NaN131.01.0
12102624841.0891.312840.296035.712058.223258.836045.752020.425225.7336NaNNaN31.726814.268840.893632.038459.158831.2504NaNNaN24.018069.856017.985632.120025.646446.337644.366443.0208NaNNaN25.812046.27844.795241.004018.067228.558417.862033.706421.004845.761619.260056.673626.358045.753636.200441.432026.107240.7344NaNNaN47.736054.126455.663233.126432.590822.403226.5645940.2662670.7573181.00.0235710.1758640.023571136.01.0
12433524973.4494.360838.696842.327653.302464.384844.048068.682032.1432NaNNaN32.865616.247253.719234.792064.338024.4680NaNNaN8.145640.3680-3.968423.114413.090847.92964.332035.3000NaNNaN8.145640.36800.224437.43689.489625.3984-1.266026.62965.428834.29526.844841.284810.438843.984828.111237.39766.043238.4512NaNNaN54.058848.801665.946022.135237.660819.53368.1539080.8428221.5914151.00.3311110.000000NaN137.01.0
13989025595.6489.554839.083243.429230.731253.979649.444814.805626.2432NaNNaN17.432427.395245.324039.920815.843654.1128NaNNaN35.757641.5592NaNNaN29.433633.098431.718448.502445.122462.167235.757641.55920.994839.603215.922829.746415.306027.598418.464439.869614.707254.860016.774850.985623.824847.128819.566043.4496NaNNaN23.949641.554436.340831.181646.140053.805635.7915780.20348810.3939742.00.0188790.000000NaN147.01.0
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "4418 1 176.76 89.2344 43.1432 12.7356 72.4264 41.0100 \n", "12201 1 488.08 89.4348 42.1136 14.8872 60.0056 38.8380 \n", "16483 1 659.36 101.1312 41.6400 66.6408 61.2456 65.7336 \n", "27344 1 1093.80 87.1824 41.7352 18.1668 64.4352 39.3312 \n", "29753 1 1190.16 92.1264 38.9536 19.3500 54.7016 49.6296 \n", "56078 1 2243.16 86.8812 44.1416 13.6692 68.6040 42.4776 \n", "67066 1 2682.68 91.7532 39.0696 23.9244 60.1184 53.9220 \n", "73982 2 2959.32 91.3824 39.2240 29.4516 51.5744 55.9548 \n", "98879 2 3955.20 86.3016 38.5376 51.9936 34.6272 42.8700 \n", "117217 2 4688.72 93.6876 40.1840 15.8316 75.2896 49.1016 \n", "121026 2 4841.08 91.3128 40.2960 35.7120 58.2232 58.8360 \n", "124335 2 4973.44 94.3608 38.6968 42.3276 53.3024 64.3848 \n", "139890 2 5595.64 89.5548 39.0832 43.4292 30.7312 53.9796 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "4418 58.8976 48.4584 40.9808 29.9100 31.9096 15.5784 61.7808 \n", "12201 58.7016 52.3488 39.1992 28.7604 28.3064 8.0796 48.0784 \n", "16483 47.3912 74.8644 34.2560 75.7188 26.3896 27.5664 56.9176 \n", "27344 50.3256 10.2048 32.7296 57.2208 41.7944 44.1408 34.9896 \n", "29753 51.9928 55.6032 36.8200 24.5328 23.6600 15.0516 38.2616 \n", "56078 52.8176 50.6280 39.8784 34.0152 33.7248 12.5904 47.0608 \n", "67066 48.9056 53.6376 26.2224 32.9388 25.3240 23.7204 24.2776 \n", "73982 48.0952 62.1876 31.5896 55.9188 26.2144 4.7496 30.3312 \n", "98879 39.0688 9.6252 44.9400 NaN NaN 32.3616 19.2896 \n", "117217 59.0504 53.8308 42.0976 NaN NaN 13.6968 41.5352 \n", "121026 45.7520 20.4252 25.7336 NaN NaN 31.7268 14.2688 \n", "124335 44.0480 68.6820 32.1432 NaN NaN 32.8656 16.2472 \n", "139890 49.4448 14.8056 26.2432 NaN NaN 17.4324 27.3952 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "4418 28.9692 45.8976 10.8684 40.0832 15.0732 37.1216 5.1240 \n", "12201 37.3908 44.5304 8.0688 48.1480 9.9564 37.8424 16.4064 \n", "16483 58.0536 45.8032 62.2416 39.9184 55.2300 27.8584 17.5884 \n", "27344 17.1288 39.9992 8.9988 30.4144 14.9388 17.1008 26.0916 \n", "29753 42.5604 36.0304 13.9284 28.5000 12.5928 14.6424 28.0356 \n", "56078 35.8164 47.9080 12.4176 31.7128 20.8920 56.4576 28.3920 \n", "67066 42.2424 44.4088 15.6588 18.5792 20.3196 43.0264 14.0760 \n", "73982 33.2496 39.5912 32.1756 27.8720 7.2216 16.0280 6.3564 \n", "98879 14.3040 35.4184 33.3216 25.5128 15.0228 20.9504 5.3808 \n", "117217 32.8848 51.2432 40.6488 30.0432 NaN NaN 12.6096 \n", "121026 40.8936 32.0384 59.1588 31.2504 NaN NaN 24.0180 \n", "124335 53.7192 34.7920 64.3380 24.4680 NaN NaN 8.1456 \n", "139890 45.3240 39.9208 15.8436 54.1128 NaN NaN 35.7576 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x \\\n", "4418 61.5696 6.8004 41.7656 NaN NaN NaN \n", "12201 17.3600 6.3096 35.6648 NaN NaN NaN \n", "16483 39.0392 12.9468 53.2672 NaN NaN NaN \n", "27344 67.1160 8.3376 38.5528 NaN NaN NaN \n", "29753 31.7720 10.1076 41.2696 NaN NaN NaN \n", "56078 65.9024 11.3292 37.6912 NaN NaN NaN \n", "67066 37.3648 9.5532 36.5432 NaN NaN NaN \n", "73982 41.2136 17.8644 37.2440 NaN NaN NaN \n", "98879 15.2384 4.4640 34.9560 23.9040 44.0848 NaN \n", "117217 48.7112 10.2204 37.9640 16.8984 61.4096 24.9816 \n", "121026 69.8560 17.9856 32.1200 25.6464 46.3376 44.3664 \n", "124335 40.3680 -3.9684 23.1144 13.0908 47.9296 4.3320 \n", "139890 41.5592 NaN NaN 29.4336 33.0984 31.7184 \n", "\n", " Home_13_y Home_14_x Home_14_y ball_x ball_y Away_25_x \\\n", "4418 NaN NaN NaN 15.2712 61.7568 1.2396 \n", "12201 NaN NaN NaN 6.5580 36.5160 2.3316 \n", "16483 NaN NaN NaN 13.0092 53.2904 4.1676 \n", "27344 NaN NaN NaN 10.3872 33.1424 3.8220 \n", "29753 NaN NaN NaN 24.6168 23.6496 3.0540 \n", "56078 NaN NaN NaN 12.6684 47.7416 2.1936 \n", "67066 NaN NaN NaN 15.6792 18.4888 4.0104 \n", "73982 NaN NaN NaN 6.3708 40.8568 2.7444 \n", "98879 NaN NaN NaN 4.6152 33.9928 1.8072 \n", "117217 68.9048 NaN NaN 12.8364 50.4360 2.1888 \n", "121026 43.0208 NaN NaN 25.8120 46.2784 4.7952 \n", "124335 35.3000 NaN NaN 8.1456 40.3680 0.2244 \n", "139890 48.5024 45.1224 62.1672 35.7576 41.5592 0.9948 \n", "\n", " Away_25_y Away_15_x Away_15_y Away_16_x Away_16_y Away_17_x \\\n", "4418 43.2752 6.7500 35.9824 5.9232 41.4272 5.3892 \n", "12201 40.3192 8.3508 33.7896 6.5988 35.7232 6.4284 \n", "16483 42.8440 14.7300 37.9832 11.2320 43.6728 11.4984 \n", "27344 38.0144 24.4308 60.7608 9.9252 34.1216 8.0184 \n", "29753 37.4104 12.6384 19.9912 13.5480 29.2376 12.0768 \n", "56078 41.4696 9.7428 33.0792 9.6372 38.3760 8.3124 \n", "67066 36.1312 13.9896 20.2760 9.3360 33.5616 10.3080 \n", "73982 41.3576 4.2372 22.4352 4.8828 31.6624 3.7728 \n", "98879 36.4120 6.3540 30.7448 8.3532 40.7712 6.1692 \n", "117217 40.7768 10.1400 38.4248 10.1352 38.4816 9.4632 \n", "121026 41.0040 18.0672 28.5584 17.8620 33.7064 21.0048 \n", "124335 37.4368 9.4896 25.3984 -1.2660 26.6296 5.4288 \n", "139890 39.6032 15.9228 29.7464 15.3060 27.5984 18.4644 \n", "\n", " Away_17_y Away_18_x Away_18_y Away_19_x Away_19_y Away_20_x \\\n", "4418 49.6744 6.8652 60.6816 11.5932 38.6544 9.8928 \n", "12201 46.4688 10.9176 57.9616 13.4808 34.9488 12.9936 \n", "16483 51.4880 36.6696 58.9584 63.9660 31.2696 20.4060 \n", "27344 39.2304 13.2540 51.6048 14.8188 40.5552 18.6240 \n", "29753 38.3864 11.8140 41.3768 18.0384 22.6400 20.9016 \n", "56078 45.5016 11.7240 63.5288 15.8124 32.6072 18.2160 \n", "67066 38.5128 9.6936 45.1272 14.6256 23.3424 18.3372 \n", "73982 37.2168 6.7716 43.0744 14.7588 28.0568 11.0328 \n", "98879 38.4368 7.9884 45.2904 13.1844 33.2592 16.2024 \n", "117217 47.5456 12.4680 69.9824 12.9000 64.4872 19.1904 \n", "121026 45.7616 19.2600 56.6736 26.3580 45.7536 36.2004 \n", "124335 34.2952 6.8448 41.2848 10.4388 43.9848 28.1112 \n", "139890 39.8696 14.7072 54.8600 16.7748 50.9856 23.8248 \n", "\n", " Away_20_y Away_21_x Away_21_y Away_22_x Away_22_y Away_23_x \\\n", "4418 53.6088 11.0784 44.4784 18.1284 60.6552 37.4964 \n", "12201 48.7032 15.0960 40.7152 19.1748 51.6248 38.5152 \n", "16483 46.3936 35.5920 38.3232 73.2060 64.7120 77.6340 \n", "27344 58.1008 12.8640 43.2800 28.3416 41.1200 21.6264 \n", "29753 36.9336 18.8028 27.2640 22.4664 54.2024 47.0148 \n", "56078 44.2304 14.0940 53.2208 20.8188 60.2800 40.1676 \n", "67066 29.7848 17.7864 37.2848 20.6772 50.4344 50.5416 \n", "73982 31.0512 10.0524 37.1088 23.1012 47.5288 54.4308 \n", "98879 47.7312 9.8808 39.5720 NaN NaN 21.3288 \n", "117217 48.0384 17.6412 56.5608 NaN NaN 48.9984 \n", "121026 41.4320 26.1072 40.7344 NaN NaN 47.7360 \n", "124335 37.3976 6.0432 38.4512 NaN NaN 54.0588 \n", "139890 47.1288 19.5660 43.4496 NaN NaN 23.9496 \n", "\n", " Away_23_y Away_24_x Away_24_y Away_26_x Away_26_y distance \\\n", "4418 57.2328 32.2008 35.1632 NaN NaN 26.581345 \n", "12201 58.7088 28.0848 29.6264 NaN NaN 7.426010 \n", "16483 44.1040 75.4080 55.1432 NaN NaN 18.597688 \n", "27344 44.7488 11.0736 29.7216 NaN NaN 12.446710 \n", "29753 54.0720 48.4500 38.4328 NaN NaN 29.552029 \n", "56078 34.5504 30.3804 53.3064 NaN NaN 14.846573 \n", "67066 26.2856 23.3520 32.2592 NaN NaN 26.618960 \n", "73982 51.0536 56.1504 27.5168 NaN NaN 6.428157 \n", "98879 29.5368 36.1884 14.3280 6.1344 17.9936 7.575389 \n", "117217 58.9608 35.8188 46.9456 20.9604 37.5144 16.543375 \n", "121026 54.1264 55.6632 33.1264 32.5908 22.4032 26.564594 \n", "124335 48.8016 65.9460 22.1352 37.6608 19.5336 8.153908 \n", "139890 41.5544 36.3408 31.1816 46.1400 53.8056 35.791578 \n", "\n", " angle distance_nearest_defender number_blocking_defenders \\\n", "4418 0.159782 3.062207 2.0 \n", "12201 0.854438 0.793849 1.0 \n", "16483 0.278761 2.351842 2.0 \n", "27344 0.492677 1.082717 1.0 \n", "29753 0.206422 6.655422 1.0 \n", "56078 0.420855 4.898197 1.0 \n", "67066 0.163513 2.459437 1.0 \n", "73982 1.030677 2.253528 1.0 \n", "98879 0.654387 3.684146 1.0 \n", "117217 0.346205 4.442172 1.0 \n", "121026 0.266267 0.757318 1.0 \n", "124335 0.842822 1.591415 1.0 \n", "139890 0.203488 10.393974 2.0 \n", "\n", " xG distance_nearest_attacker non_shot_xG Home Possession \\\n", "4418 0.019134 0.308136 0.019134 7.0 \n", "12201 0.330727 0.886704 0.330727 16.0 \n", "16483 0.048740 0.066573 0.048740 21.0 \n", "27344 0.142581 0.451302 0.142581 33.0 \n", "29753 0.031972 0.084641 0.031972 35.0 \n", "56078 0.155117 0.685254 0.155117 65.0 \n", "67066 0.024509 0.092673 0.024509 79.0 \n", "73982 0.467064 0.357090 0.467064 89.0 \n", "98879 0.335298 0.974995 0.335298 112.0 \n", "117217 0.113531 1.739647 NaN 131.0 \n", "121026 0.023571 0.175864 0.023571 136.0 \n", "124335 0.331111 0.000000 NaN 137.0 \n", "139890 0.018879 0.000000 NaN 147.0 \n", "\n", " Shot Indicator \n", "4418 1.0 \n", "12201 1.0 \n", "16483 1.0 \n", "27344 1.0 \n", "29753 1.0 \n", "56078 1.0 \n", "67066 1.0 \n", "73982 1.0 \n", "98879 1.0 \n", "117217 1.0 \n", "121026 1.0 \n", "124335 1.0 \n", "139890 1.0 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create shot indicator and merge to tracking data\n", "home_shots['Shot Indicator'] = 1\n", "home_tracking_frames = pd.merge(home_tracking_frames, home_shots[['Start Time [s]', 'Shot Indicator']], how='left', left_on='Time [s]', right_on='Start Time [s]')\n", "home_tracking_frames.drop(['Start Time [s]'], axis=1, inplace=True)\n", "home_tracking_frames[home_tracking_frames['Shot Indicator'] == 1]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:10:50.923407Z", "start_time": "2021-01-03T15:10:50.576607Z" } }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PeriodTime [s]Home_11_xHome_11_yHome_1_xHome_1_yHome_2_xHome_2_yHome_3_xHome_3_yHome_4_xHome_4_yHome_5_xHome_5_yHome_6_xHome_6_yHome_7_xHome_7_yHome_8_xHome_8_yHome_9_xHome_9_yHome_10_xHome_10_yHome_12_xHome_12_yHome_13_xHome_13_yHome_14_xHome_14_yball_xball_yAway_25_xAway_25_yAway_15_xAway_15_yAway_16_xAway_16_yAway_17_xAway_17_yAway_18_xAway_18_yAway_19_xAway_19_yAway_20_xAway_20_yAway_21_xAway_21_yAway_22_xAway_22_yAway_23_xAway_23_yAway_24_xAway_24_yAway_26_xAway_26_ydistanceangledistance_nearest_defendernumber_blocking_defendersxGdistance_nearest_attackernon_shot_xGAway PossessionShot Indicator
185141740.60115.729241.3944101.709651.4880102.680445.6096104.286034.5560101.415618.236094.142444.688894.028440.559291.112429.806487.34447.348880.876451.500069.025231.6600NaNNaNNaNNaNNaNNaN95.391652.040826.577640.183273.792813.048063.090030.112065.169637.277677.961657.663295.690420.179297.318841.229676.550435.105695.558452.0760106.214438.1336103.099249.0856NaNNaN27.3962450.2395096.3421380.00.0553480.1704740.05534826.01.0
5304812121.96116.996439.2760109.155642.4840109.768831.2960111.446430.9216106.713621.781699.872430.628097.832441.474499.097222.016888.856458.674470.838429.127269.064840.7312NaNNaNNaNNaNNaNNaN110.476843.578424.316842.475280.636413.648067.179627.230463.766844.987264.668061.3024101.672421.838485.125634.197671.644845.716094.476052.7136107.815230.7568110.546443.5840NaNNaN10.1733120.6580781.7155990.00.2937080.0698250.29370862.01.0
6336112534.48119.618437.8928108.705649.2408110.289658.3304111.536441.9384113.863234.4856107.986840.0192109.428045.0960111.472840.4592101.035258.705671.140824.766459.856040.1104NaNNaNNaNNaNNaNNaN111.813640.684812.514843.764068.956822.058457.340830.700058.932041.195262.442055.6864109.196431.500091.642837.850481.447647.8312111.271263.6040111.786040.5560102.445243.8400NaNNaN8.2149920.8360340.4087051.00.2957560.1317240.29575671.01.0
6477112590.88118.653639.5288108.027650.3304108.710441.7848105.514838.0216108.553237.594497.723243.479294.821637.783298.740833.592891.958451.703284.577252.140864.213235.7504NaNNaNNaNNaNNaNNaN92.349635.620020.970041.008082.014016.492062.368829.939260.764442.1768110.304039.4992110.252434.347292.371235.646477.720435.613689.328049.404077.700023.0112102.351665.0192NaNNaN27.9951610.2567703.2848470.00.0371920.0341100.03719273.01.0
6988622795.48118.254041.0528107.098861.2120110.234452.8184107.858439.8696108.844835.528898.352064.0488104.376053.7040104.280046.540099.205245.753675.661256.563270.048839.9408NaNNaNNaNNaNNaNNaN94.497652.836025.438840.229683.408424.394467.350039.613671.536856.0128103.222868.9864100.558826.169685.290042.316094.498852.7880110.202066.6744109.178448.0176108.218434.7400NaNNaN28.5505740.2286158.5042281.00.0457880.0480150.04578877.01.0
8619023447.64118.927241.1416110.262044.1624109.140034.3856109.758036.4784112.762838.5080106.605646.0120107.928041.0328111.156047.7968114.733264.3152100.038039.2408108.908456.8624NaNNaNNaNNaNNaNNaN100.659645.861640.810840.620093.086428.1600108.602431.7000110.101234.517683.805652.550496.702043.5840101.426466.4248108.002451.4328115.113671.4016104.930443.2512112.850440.5792NaNNaN20.2091420.3439135.9479020.00.1254564.566187NaN90.01.0
9016423606.60117.825636.060097.882847.4856114.238832.6272106.759222.9080109.870827.5520110.494843.1968109.340433.9176102.625229.936073.801221.6016103.578038.357655.376426.6400NaNNaNNaNNaNNaNNaN112.881626.560017.493639.623271.899217.972859.674832.572856.828448.829676.036858.1536112.946426.580899.556849.493676.797642.1960NaNNaN107.916049.640099.904824.9312113.574032.411215.2087220.2345473.1700130.00.1275390.0680560.12753991.01.0
11175724470.32119.275239.9336104.910062.4872117.130853.5912117.540042.9600NaNNaN108.622835.5400111.543642.3448113.776836.1216NaNNaN95.161252.692072.255634.9448111.064851.5024114.074445.2552NaNNaN109.612831.259229.024439.403286.014822.485671.031631.993666.152444.6920121.018854.352099.446462.9528104.731245.960087.616843.6288NaNNaN117.884447.9832109.593631.1280117.193237.897613.5755480.4183284.3937852.00.1245020.1325970.124502120.01.0
11500824600.36119.031641.1160101.523650.4768101.830847.2080102.214830.2440NaNNaN101.272831.699297.755645.374499.302432.6424NaNNaN95.704836.5312101.222425.9176101.491248.9832101.103627.7488NaNNaN106.074041.704829.575238.133691.923630.6560100.746049.250465.841642.592077.095249.127296.204041.6240106.074041.704897.542038.7176NaNNaN99.592847.6608100.894832.5512101.817628.896814.0299610.5068836.9490980.00.2916220.000000NaN120.01.0
13256925302.80118.614040.4328109.804830.8808109.966829.4800108.907232.1056NaNNaN107.562042.0824108.519632.7824109.268431.5272NaNNaN102.879643.0448NaNNaN108.471633.8584108.396038.7736108.48047.484098.217630.288030.960042.380894.914033.4280108.021636.3912109.621236.944098.217630.2880108.682836.0584108.644433.946497.933242.9760NaNNaN106.296048.7168108.286842.8752109.597229.675223.8494420.27938410.5996810.00.1345750.000000NaN130.01.0
13605925442.40118.718439.7176113.894434.5312113.998845.9784114.788438.9888NaNNaN108.252038.0960108.567645.8416107.370058.0152NaNNaN86.208053.1856NaNNaN94.435236.9800105.048048.4744112.71656.2368113.930436.764843.272039.9992102.757223.045673.798836.832080.562053.393699.931242.7688114.751244.692093.103240.680090.757254.8608NaNNaN108.570066.6752113.776830.3336113.941236.70886.8779770.9183002.2338900.00.4905060.0570320.490506135.01.0
\n", "
" ], "text/plain": [ " Period Time [s] Home_11_x Home_11_y Home_1_x Home_1_y Home_2_x \\\n", "18514 1 740.60 115.7292 41.3944 101.7096 51.4880 102.6804 \n", "53048 1 2121.96 116.9964 39.2760 109.1556 42.4840 109.7688 \n", "63361 1 2534.48 119.6184 37.8928 108.7056 49.2408 110.2896 \n", "64771 1 2590.88 118.6536 39.5288 108.0276 50.3304 108.7104 \n", "69886 2 2795.48 118.2540 41.0528 107.0988 61.2120 110.2344 \n", "86190 2 3447.64 118.9272 41.1416 110.2620 44.1624 109.1400 \n", "90164 2 3606.60 117.8256 36.0600 97.8828 47.4856 114.2388 \n", "111757 2 4470.32 119.2752 39.9336 104.9100 62.4872 117.1308 \n", "115008 2 4600.36 119.0316 41.1160 101.5236 50.4768 101.8308 \n", "132569 2 5302.80 118.6140 40.4328 109.8048 30.8808 109.9668 \n", "136059 2 5442.40 118.7184 39.7176 113.8944 34.5312 113.9988 \n", "\n", " Home_2_y Home_3_x Home_3_y Home_4_x Home_4_y Home_5_x Home_5_y \\\n", "18514 45.6096 104.2860 34.5560 101.4156 18.2360 94.1424 44.6888 \n", "53048 31.2960 111.4464 30.9216 106.7136 21.7816 99.8724 30.6280 \n", "63361 58.3304 111.5364 41.9384 113.8632 34.4856 107.9868 40.0192 \n", "64771 41.7848 105.5148 38.0216 108.5532 37.5944 97.7232 43.4792 \n", "69886 52.8184 107.8584 39.8696 108.8448 35.5288 98.3520 64.0488 \n", "86190 34.3856 109.7580 36.4784 112.7628 38.5080 106.6056 46.0120 \n", "90164 32.6272 106.7592 22.9080 109.8708 27.5520 110.4948 43.1968 \n", "111757 53.5912 117.5400 42.9600 NaN NaN 108.6228 35.5400 \n", "115008 47.2080 102.2148 30.2440 NaN NaN 101.2728 31.6992 \n", "132569 29.4800 108.9072 32.1056 NaN NaN 107.5620 42.0824 \n", "136059 45.9784 114.7884 38.9888 NaN NaN 108.2520 38.0960 \n", "\n", " Home_6_x Home_6_y Home_7_x Home_7_y Home_8_x Home_8_y Home_9_x \\\n", "18514 94.0284 40.5592 91.1124 29.8064 87.3444 7.3488 80.8764 \n", "53048 97.8324 41.4744 99.0972 22.0168 88.8564 58.6744 70.8384 \n", "63361 109.4280 45.0960 111.4728 40.4592 101.0352 58.7056 71.1408 \n", "64771 94.8216 37.7832 98.7408 33.5928 91.9584 51.7032 84.5772 \n", "69886 104.3760 53.7040 104.2800 46.5400 99.2052 45.7536 75.6612 \n", "86190 107.9280 41.0328 111.1560 47.7968 114.7332 64.3152 100.0380 \n", "90164 109.3404 33.9176 102.6252 29.9360 73.8012 21.6016 103.5780 \n", "111757 111.5436 42.3448 113.7768 36.1216 NaN NaN 95.1612 \n", "115008 97.7556 45.3744 99.3024 32.6424 NaN NaN 95.7048 \n", "132569 108.5196 32.7824 109.2684 31.5272 NaN NaN 102.8796 \n", "136059 108.5676 45.8416 107.3700 58.0152 NaN NaN 86.2080 \n", "\n", " Home_9_y Home_10_x Home_10_y Home_12_x Home_12_y Home_13_x \\\n", "18514 51.5000 69.0252 31.6600 NaN NaN NaN \n", "53048 29.1272 69.0648 40.7312 NaN NaN NaN \n", "63361 24.7664 59.8560 40.1104 NaN NaN NaN \n", "64771 52.1408 64.2132 35.7504 NaN NaN NaN \n", "69886 56.5632 70.0488 39.9408 NaN NaN NaN \n", "86190 39.2408 108.9084 56.8624 NaN NaN NaN \n", "90164 38.3576 55.3764 26.6400 NaN NaN NaN \n", "111757 52.6920 72.2556 34.9448 111.0648 51.5024 114.0744 \n", "115008 36.5312 101.2224 25.9176 101.4912 48.9832 101.1036 \n", "132569 43.0448 NaN NaN 108.4716 33.8584 108.3960 \n", "136059 53.1856 NaN NaN 94.4352 36.9800 105.0480 \n", "\n", " Home_13_y Home_14_x Home_14_y ball_x ball_y Away_25_x \\\n", "18514 NaN NaN NaN 95.3916 52.0408 26.5776 \n", "53048 NaN NaN NaN 110.4768 43.5784 24.3168 \n", "63361 NaN NaN NaN 111.8136 40.6848 12.5148 \n", "64771 NaN NaN NaN 92.3496 35.6200 20.9700 \n", "69886 NaN NaN NaN 94.4976 52.8360 25.4388 \n", "86190 NaN NaN NaN 100.6596 45.8616 40.8108 \n", "90164 NaN NaN NaN 112.8816 26.5600 17.4936 \n", "111757 45.2552 NaN NaN 109.6128 31.2592 29.0244 \n", "115008 27.7488 NaN NaN 106.0740 41.7048 29.5752 \n", "132569 38.7736 108.480 47.4840 98.2176 30.2880 30.9600 \n", "136059 48.4744 112.716 56.2368 113.9304 36.7648 43.2720 \n", "\n", " Away_25_y Away_15_x Away_15_y Away_16_x Away_16_y Away_17_x \\\n", "18514 40.1832 73.7928 13.0480 63.0900 30.1120 65.1696 \n", "53048 42.4752 80.6364 13.6480 67.1796 27.2304 63.7668 \n", "63361 43.7640 68.9568 22.0584 57.3408 30.7000 58.9320 \n", "64771 41.0080 82.0140 16.4920 62.3688 29.9392 60.7644 \n", "69886 40.2296 83.4084 24.3944 67.3500 39.6136 71.5368 \n", "86190 40.6200 93.0864 28.1600 108.6024 31.7000 110.1012 \n", "90164 39.6232 71.8992 17.9728 59.6748 32.5728 56.8284 \n", "111757 39.4032 86.0148 22.4856 71.0316 31.9936 66.1524 \n", "115008 38.1336 91.9236 30.6560 100.7460 49.2504 65.8416 \n", "132569 42.3808 94.9140 33.4280 108.0216 36.3912 109.6212 \n", "136059 39.9992 102.7572 23.0456 73.7988 36.8320 80.5620 \n", "\n", " Away_17_y Away_18_x Away_18_y Away_19_x Away_19_y Away_20_x \\\n", "18514 37.2776 77.9616 57.6632 95.6904 20.1792 97.3188 \n", "53048 44.9872 64.6680 61.3024 101.6724 21.8384 85.1256 \n", "63361 41.1952 62.4420 55.6864 109.1964 31.5000 91.6428 \n", "64771 42.1768 110.3040 39.4992 110.2524 34.3472 92.3712 \n", "69886 56.0128 103.2228 68.9864 100.5588 26.1696 85.2900 \n", "86190 34.5176 83.8056 52.5504 96.7020 43.5840 101.4264 \n", "90164 48.8296 76.0368 58.1536 112.9464 26.5808 99.5568 \n", "111757 44.6920 121.0188 54.3520 99.4464 62.9528 104.7312 \n", "115008 42.5920 77.0952 49.1272 96.2040 41.6240 106.0740 \n", "132569 36.9440 98.2176 30.2880 108.6828 36.0584 108.6444 \n", "136059 53.3936 99.9312 42.7688 114.7512 44.6920 93.1032 \n", "\n", " Away_20_y Away_21_x Away_21_y Away_22_x Away_22_y Away_23_x \\\n", "18514 41.2296 76.5504 35.1056 95.5584 52.0760 106.2144 \n", "53048 34.1976 71.6448 45.7160 94.4760 52.7136 107.8152 \n", "63361 37.8504 81.4476 47.8312 111.2712 63.6040 111.7860 \n", "64771 35.6464 77.7204 35.6136 89.3280 49.4040 77.7000 \n", "69886 42.3160 94.4988 52.7880 110.2020 66.6744 109.1784 \n", "86190 66.4248 108.0024 51.4328 115.1136 71.4016 104.9304 \n", "90164 49.4936 76.7976 42.1960 NaN NaN 107.9160 \n", "111757 45.9600 87.6168 43.6288 NaN NaN 117.8844 \n", "115008 41.7048 97.5420 38.7176 NaN NaN 99.5928 \n", "132569 33.9464 97.9332 42.9760 NaN NaN 106.2960 \n", "136059 40.6800 90.7572 54.8608 NaN NaN 108.5700 \n", "\n", " Away_23_y Away_24_x Away_24_y Away_26_x Away_26_y distance \\\n", "18514 38.1336 103.0992 49.0856 NaN NaN 27.396245 \n", "53048 30.7568 110.5464 43.5840 NaN NaN 10.173312 \n", "63361 40.5560 102.4452 43.8400 NaN NaN 8.214992 \n", "64771 23.0112 102.3516 65.0192 NaN NaN 27.995161 \n", "69886 48.0176 108.2184 34.7400 NaN NaN 28.550574 \n", "86190 43.2512 112.8504 40.5792 NaN NaN 20.209142 \n", "90164 49.6400 99.9048 24.9312 113.5740 32.4112 15.208722 \n", "111757 47.9832 109.5936 31.1280 117.1932 37.8976 13.575548 \n", "115008 47.6608 100.8948 32.5512 101.8176 28.8968 14.029961 \n", "132569 48.7168 108.2868 42.8752 109.5972 29.6752 23.849442 \n", "136059 66.6752 113.7768 30.3336 113.9412 36.7088 6.877977 \n", "\n", " angle distance_nearest_defender number_blocking_defenders \\\n", "18514 0.239509 6.342138 0.0 \n", "53048 0.658078 1.715599 0.0 \n", "63361 0.836034 0.408705 1.0 \n", "64771 0.256770 3.284847 0.0 \n", "69886 0.228615 8.504228 1.0 \n", "86190 0.343913 5.947902 0.0 \n", "90164 0.234547 3.170013 0.0 \n", "111757 0.418328 4.393785 2.0 \n", "115008 0.506883 6.949098 0.0 \n", "132569 0.279384 10.599681 0.0 \n", "136059 0.918300 2.233890 0.0 \n", "\n", " xG distance_nearest_attacker non_shot_xG Away Possession \\\n", "18514 0.055348 0.170474 0.055348 26.0 \n", "53048 0.293708 0.069825 0.293708 62.0 \n", "63361 0.295756 0.131724 0.295756 71.0 \n", "64771 0.037192 0.034110 0.037192 73.0 \n", "69886 0.045788 0.048015 0.045788 77.0 \n", "86190 0.125456 4.566187 NaN 90.0 \n", "90164 0.127539 0.068056 0.127539 91.0 \n", "111757 0.124502 0.132597 0.124502 120.0 \n", "115008 0.291622 0.000000 NaN 120.0 \n", "132569 0.134575 0.000000 NaN 130.0 \n", "136059 0.490506 0.057032 0.490506 135.0 \n", "\n", " Shot Indicator \n", "18514 1.0 \n", "53048 1.0 \n", "63361 1.0 \n", "64771 1.0 \n", "69886 1.0 \n", "86190 1.0 \n", "90164 1.0 \n", "111757 1.0 \n", "115008 1.0 \n", "132569 1.0 \n", "136059 1.0 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create shot indicator and merge to tracking data\n", "away_shots['Shot Indicator'] = 1\n", "away_tracking_frames = pd.merge(away_tracking_frames, away_shots[['Start Time [s]', 'Shot Indicator']], how='left', left_on='Time [s]', right_on='Start Time [s]')\n", "away_tracking_frames.drop(['Start Time [s]'], axis=1, inplace=True)\n", "away_tracking_frames[away_tracking_frames['Shot Indicator'] == 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sum xG and Non Shot xG\n", "\n", "Sum the shot expected goals and the non-shot expected goals using xG and non_shot_xG respectively for the possessions that the team has.\n", "\n", "### Home" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:10:50.937370Z", "start_time": "2021-01-03T15:10:50.925401Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total xG for all shots: 2.0422338503137234.\n" ] }, { "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", "
xGHome Possession
44180.0191347.0
122010.33072716.0
164830.04874021.0
273440.14258133.0
297530.03197235.0
560780.15511765.0
670660.02450979.0
739820.46706489.0
988790.335298112.0
1172170.113531131.0
1210260.023571136.0
1243350.331111137.0
1398900.018879147.0
\n", "
" ], "text/plain": [ " xG Home Possession\n", "4418 0.019134 7.0\n", "12201 0.330727 16.0\n", "16483 0.048740 21.0\n", "27344 0.142581 33.0\n", "29753 0.031972 35.0\n", "56078 0.155117 65.0\n", "67066 0.024509 79.0\n", "73982 0.467064 89.0\n", "98879 0.335298 112.0\n", "117217 0.113531 131.0\n", "121026 0.023571 136.0\n", "124335 0.331111 137.0\n", "139890 0.018879 147.0" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Sum the xG for the shots\n", "home_shot_xg = home_tracking_frames[home_tracking_frames['Shot Indicator'] == 1][['xG', 'Home Possession']]\n", "print('Total xG for all shots: {}.'.format(home_shot_xg['xG'].sum()))\n", "home_shot_xg" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:13:10.633580Z", "start_time": "2021-01-03T15:13:10.552796Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total non-shot xG for all possessions: 6.471366602506773.\n" ] }, { "data": { "text/plain": [ "Home Possession\n", "1.0 0.000173\n", "2.0 0.000373\n", "3.0 0.000130\n", "4.0 0.000085\n", "5.0 0.000184\n", " ... \n", "143.0 NaN\n", "144.0 0.000018\n", "145.0 0.000009\n", "146.0 0.001678\n", "147.0 0.014475\n", "Name: non_shot_xG, Length: 146, dtype: float64" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Sum the non-shot xG for all possessions\n", "home_non_shot_xG = home_tracking_frames.groupby('Home Possession').max()['non_shot_xG']\n", "print('Total non-shot xG for all possessions: {}.'.format(home_non_shot_xG.sum()))\n", "home_non_shot_xG" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:13:22.096982Z", "start_time": "2021-01-03T15:13:22.085015Z" }, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Combined xG and non-shot xG for all possessions: 5.3129587422610225.\n" ] }, { "data": { "text/plain": [ "Home Possession\n", "1.0 0.000173\n", "2.0 0.000373\n", "3.0 0.000130\n", "4.0 0.000085\n", "5.0 0.000184\n", " ... \n", "143.0 NaN\n", "144.0 0.000018\n", "145.0 0.000009\n", "146.0 0.001678\n", "147.0 0.018879\n", "Name: non_shot_xG, Length: 146, dtype: float64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# If a possession had a shot, then attribute the xG to that possession\n", "home_xG_combined = home_non_shot_xG.copy()\n", "row_count=0\n", "for possession in list(home_shot_xg['Home Possession']):\n", " for index in home_xG_combined.index:\n", " if possession == index:\n", " home_xG_combined[index] = home_shot_xg['xG'].iloc[row_count]\n", " row_count+=1\n", "print('Combined xG and non-shot xG for all possessions: {}.'.format(home_xG_combined.sum()))\n", "home_xG_combined" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Away" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:13:32.513286Z", "start_time": "2021-01-03T15:13:32.501334Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total xG for all shots: 2.0219916974382524.\n" ] }, { "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", "
xGAway Possession
185140.05534826.0
530480.29370862.0
633610.29575671.0
647710.03719273.0
698860.04578877.0
861900.12545690.0
901640.12753991.0
1117570.124502120.0
1150080.291622120.0
1325690.134575130.0
1360590.490506135.0
\n", "
" ], "text/plain": [ " xG Away Possession\n", "18514 0.055348 26.0\n", "53048 0.293708 62.0\n", "63361 0.295756 71.0\n", "64771 0.037192 73.0\n", "69886 0.045788 77.0\n", "86190 0.125456 90.0\n", "90164 0.127539 91.0\n", "111757 0.124502 120.0\n", "115008 0.291622 120.0\n", "132569 0.134575 130.0\n", "136059 0.490506 135.0" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "away_shot_xg = away_tracking_frames[away_tracking_frames['Shot Indicator'] == 1][['xG', 'Away Possession']]\n", "print('Total xG for all shots: {}.'.format(away_shot_xg['xG'].sum()))\n", "away_shot_xg" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:13:32.953524Z", "start_time": "2021-01-03T15:13:32.875683Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total non-shot xG for all possessions: 3.8990711322285203.\n" ] }, { "data": { "text/plain": [ "Away Possession\n", "1.0 0.002531\n", "2.0 0.000991\n", "3.0 0.002739\n", "4.0 0.003080\n", "5.0 0.007574\n", "6.0 0.000847\n", "7.0 0.000031\n", "8.0 0.000782\n", "9.0 0.000069\n", "10.0 0.000391\n", "Name: non_shot_xG, dtype: float64" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "away_non_shot_xG = away_tracking_frames.groupby('Away Possession').max()['non_shot_xG']\n", "print('Total non-shot xG for all possessions: {}.'.format(away_non_shot_xG.sum()))\n", "away_non_shot_xG[:10]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2021-01-03T15:13:35.530352Z", "start_time": "2021-01-03T15:13:35.519380Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Combined xG and non-shot xG for all possessions: 3.4645735037493606.\n" ] }, { "data": { "text/plain": [ "Away Possession\n", "1.0 0.002531\n", "2.0 0.000991\n", "3.0 0.002739\n", "4.0 0.003080\n", "5.0 0.007574\n", " ... \n", "131.0 0.000900\n", "132.0 0.016164\n", "133.0 0.015819\n", "134.0 0.006342\n", "135.0 0.490506\n", "Name: non_shot_xG, Length: 134, dtype: float64" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "away_xG_combined = away_non_shot_xG.copy()\n", "row_count=0\n", "for possession in list(away_shot_xg['Away Possession']):\n", " for index in away_xG_combined.index:\n", " if possession == index:\n", " away_xG_combined[index] = away_shot_xg['xG'].iloc[row_count]\n", " row_count+=1\n", "print('Combined xG and non-shot xG for all possessions: {}.'.format(away_xG_combined.sum()))\n", "away_xG_combined" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "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.6.2" }, "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": false } }, "nbformat": 4, "nbformat_minor": 2 }