{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Second Spectrum Data Engineering\n", "##### Notebook to engineer [Second Spectrum](https://www.secondspectrum.com/index.html) Tracking data using [pandas](http://pandas.pydata.org/).\n", "\n", "### By [Edd Webster](https://www.twitter.com/eddwebster)\n", "Notebook first written: 20/01/2022
\n", "Notebook last updated: 01/02/2022\n", "\n", "![Watford F.C.](../../img/logos/second_spectrum_logo.jpeg)\n", "\n", "![Second Spectrum](../../img/club_badges/premier_league/watford_fc_logo_small.png)\n", "\n", "Click [here](#section4) to jump straight into the Data Engineering section and skip the [Notebook Brief](#section2) and [Data Sources](#section3) sections." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "\n", "\n", "## Introduction\n", "This notebook parses and engineers [Second Spectrum](https://www.secondspectrum.com/index.html) Tracking data for two matches, that have been provided by [Watford F.C](https://www.watfordfc.com/), using [pandas](http://pandas.pydata.org/) for data manipulation through DataFrames.\n", "\n", "For more information about this notebook and the author, I am available through all the following channels:\n", "* [eddwebster.com](https://www.eddwebster.com/);\n", "* edd.j.webster@gmail.com;\n", "* [@eddwebster](https://www.twitter.com/eddwebster);\n", "* [linkedin.com/in/eddwebster](https://www.linkedin.com/in/eddwebster/);\n", "* [github/eddwebster](https://github.com/eddwebster/); and\n", "* [public.tableau.com/profile/edd.webster](https://public.tableau.com/profile/edd.webster).\n", "\n", "A static version of this notebook can be found [here](https://nbviewer.org/github/eddwebster/watford/blob/main/notebooks/2_data_engineering/Second%20Spectrum%20Data%20Engineering.ipynb). This notebook has an accompanying [`watford`](https://github.com/eddwebster/watford) GitHub repository and for my full repository of football analysis, see my [`football_analysis`](https://github.com/eddwebster/football_analytics) GitHub repository." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "\n", "## Notebook Contents\n", "1. [Notebook Dependencies](#section1)
\n", "2. [Notebook Brief](#section2)
\n", "3. [Data Sources](#section3)
\n", " 1. [Introduction](#section3.1)
\n", " 2. [Data Dicitonary](#section3.2)
\n", " 3. [Import the Data](#section3.3)
\n", " 4. [Initial Data Handling](#section3.4)
\n", "4. [Data Engineering](#section4)
\n", " 1. [Reset Index](#section4.1)
\n", " 2. [Rename Columns](#section4.2)
\n", " 3. [Rename Player Columns Using Metadata](#section4.3)
\n", " 4. [Separate Home and Away DataFrames](#section4.4)
\n", " 5. [Calculate Player Velocities](#section4.5)
\n", " 6. [Reverse direction of players](#section4.6)
\n", "5. [Summary](#section5)
\n", "6. [Next Steps](#section6)
\n", "7. [References](#section7)
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "___\n", "\n", "\n", "\n", "## 1. Notebook Dependencies\n", "\n", "This notebook was written using [Python 3](https://docs.python.org/3.7/) and requires the following libraries:\n", "* [`Jupyter notebooks`](https://jupyter.org/) for this notebook environment with which this project is presented;\n", "* [`NumPy`](http://www.numpy.org/) for multidimensional array computing; and\n", "* [`pandas`](http://pandas.pydata.org/) for data analysis and manipulation.\n", "\n", "All packages used for this notebook can be obtained by downloading and installing the [Conda](https://anaconda.org/anaconda/conda) distribution, available on all platforms (Windows, Linux and Mac OSX). Step-by-step guides on how to install Anaconda can be found for Windows [here](https://medium.com/@GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444) and Mac [here](https://medium.com/@GalarnykMichael/install-python-on-mac-anaconda-ccd9f2014072), as well as in the Anaconda documentation itself [here](https://docs.anaconda.com/anaconda/install/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import Libraries and Modules" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Setup Complete\n" ] } ], "source": [ "# Python ≥3.5 (ideally)\n", "import platform\n", "import sys, getopt\n", "assert sys.version_info >= (3, 5)\n", "import csv\n", "\n", "# Import Dependencies\n", "%matplotlib inline\n", "\n", "# Math Operations\n", "import numpy as np\n", "import math\n", "from math import pi\n", "\n", "# Datetime\n", "import datetime\n", "from datetime import date\n", "import time\n", "\n", "# Data Preprocessing\n", "import pandas as pd\n", "import pandas_profiling as pp\n", "import os\n", "import re\n", "import chardet\n", "import random\n", "from io import BytesIO\n", "from pathlib import Path\n", "\n", "# Kloppy\n", "from kloppy import secondspectrum\n", "\n", "# Reading Directories\n", "import glob\n", "import os\n", "\n", "# Working with JSON\n", "import json\n", "from pandas import json_normalize\n", "\n", "# Data Visualisation\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import matplotlib.animation as animation\n", "from matplotlib.colors import LinearSegmentedColormap\n", "from matplotlib import patches\n", "import seaborn as sns\n", "import missingno as msno\n", "import moviepy.editor as mpy\n", "from moviepy.video.io.bindings import mplfig_to_npimage\n", "\n", "# Requests and downloads\n", "import tqdm\n", "import requests\n", "\n", "# Machine Learning\n", "import scipy.signal as signal\n", "from scipy.spatial import Voronoi, voronoi_plot_2d, Delaunay\n", "\n", "# Display in Jupyter\n", "from IPython.display import Image, YouTubeVideo\n", "from IPython.core.display import HTML\n", "\n", "# Ignore Warnings\n", "import warnings\n", "warnings.filterwarnings(action=\"ignore\", message=\"^internal gelsd\")\n", "\n", "# Print message\n", "print('Setup Complete')" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python: 3.7.6\n", "NumPy: 1.19.1\n", "pandas: 1.1.3\n", "matplotlib: 3.3.1\n" ] } ], "source": [ "# Python / module versions used here for reference\n", "print('Python: {}'.format(platform.python_version()))\n", "print('NumPy: {}'.format(np.__version__))\n", "print('pandas: {}'.format(pd.__version__))\n", "print('matplotlib: {}'.format(mpl.__version__))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Defined Filepaths" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "# Set up initial paths to subfolders\n", "base_dir = os.path.join('..', '..')\n", "data_dir = os.path.join(base_dir, 'data')\n", "data_dir_second_spectrum = os.path.join(base_dir, 'data', 'second_spectrum')\n", "data_dir_opta = os.path.join(base_dir, 'data', 'opta')\n", "scripts_dir = os.path.join(base_dir, 'scripts')\n", "scripts_dir_second_spectrum = os.path.join(base_dir, 'scripts', 'second_spectrum')\n", "scripts_dir_metrica_sports = os.path.join(base_dir, 'scripts', 'metrica_sports')\n", "img_dir = os.path.join(base_dir, 'img')\n", "fig_dir = os.path.join(base_dir, 'img', 'fig')\n", "fig_dir_second_spectrum = os.path.join(base_dir, 'img', 'fig', 'second_spectrum')\n", "video_dir = os.path.join(base_dir, 'video')\n", "video_dir_second_spectrum = os.path.join(base_dir, 'video', 'fig', 'second_spectrum')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom Libraries for Tracking Data\n", "Custom libraries for working with the [Second Spectrum](https://www.secondspectrum.com/index.html) data, that were initially written by [Laurie Shaw](https://twitter.com/EightyFivePoint), to work with the [Metrica Sports](https://metrica-sports.com/) data. See the following for his original code [[link](https://github.com/Friends-of-Tracking-Data-FoTD/LaurieOnTracking)].\n", "\n", "The modifications to this data include the ability to create Pitch Control models without Tracking data." ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "# Custom libraries for working with Tracking data\n", "\n", "## Define path of scripts\n", "sys.path.insert(0, os.path.abspath(scripts_dir_second_spectrum))\n", "\n", "## Second Spectrum scripts - custom scripts derived from Laurie Shaw's Metrica scripts\n", "import Second_Spectrum_IO as sio\n", "import Second_Spectrum_Viz as sviz\n", "import Second_Spectrum_Velocities as svel\n", "import Second_Spectrum_PitchControl as spc\n", "import Second_Spectrum_EPV as sepv" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"\\n## Laurie Shaw's custom libraries for working with Metrica Sports data\\nimport Metrica_IO as mio\\nimport Metrica_Viz as mviz\\nimport Metrica_Velocities as mvel\\nimport Metrica_PitchControl as mpc\\nimport Metrica_EPV as mepv\\n\"" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\"\n", "## Laurie Shaw's custom libraries for working with Metrica Sports data\n", "import Metrica_IO as mio\n", "import Metrica_Viz as mviz\n", "import Metrica_Velocities as mvel\n", "import Metrica_PitchControl as mpc\n", "import Metrica_EPV as mepv\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom Functions" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "# Define function to read in Tracking data using Kloppy\n", "def read_in_tracking_data(filename):\n", " \n", " \"\"\"\n", " Function to read in Second Spectrum Tracking data as a pandas DataFrame using Kloppy. Written by Edd Webster / @eddwebster\n", " \"\"\"\n", " \n", " # Read in exported CSV file if exists, if not, read in the raw JSON and XML files using Kloppy\n", "\n", " ## If not already saved as a CSV file\n", " if not os.path.exists(os.path.join(data_dir_second_spectrum, 'raw', 'data', f'g{filename}_SecondSpectrum_Data.csv')):\n", "\n", " ### Load meta data (XML) and raw data (JSONL) files\n", " dataset = secondspectrum.load(\n", " meta_data = f'../../data/second_spectrum/raw/metadata/g{filename}_SecondSpectrum_Metadata.xml',\n", " raw_data = f'../../data/second_spectrum/raw/data/g{filename}_SecondSpectrum_Data.jsonl',\n", " #meta_data = os.path.join(data_dir_second_spectrum, 'raw', 'data', f'{filename}_SecondSpectrum_Metadata.xml')\n", " #raw_data = os.path.join(data_dir_second_spectrum, 'raw', 'data', f'{filename}_SecondSpectrum_Data.jsonl')\n", "\n", " ### Optional arguments\n", " additional_meta_data = f'../../data/second_spectrum/raw/metadata/g{filename}_SecondSpectrum_Metadata.json',\n", " #additional_meta_data = os.path.join(data_dir_second_spectrum, 'raw', 'data', f'{filename}_SecondSpectrum_Metadata.json')\n", " #sample_rate=1/25,\n", " #limit=100,\n", " coordinates='secondspectrum',\n", " #only_alive=True\n", " )\n", "\n", " ### Convert DataFrame to pandas\n", " df_tracking = dataset.to_pandas()\n", "\n", " ### Export raw DataFrame\n", " df_tracking.to_csv(os.path.join(data_dir_second_spectrum, 'raw', 'data', f'g{filename}_SecondSpectrum_Data.csv'), index=None, header=True)\n", "\n", " ## If already, read in CSV file\n", " else:\n", " df_tracking = pd.read_csv(os.path.join(data_dir_second_spectrum, 'raw', 'data', f'g{filename}_SecondSpectrum_Data.csv')) \n", " \n", " \n", " ## Return DataFrame\n", " return df_tracking" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "# Define function to create separate DataFrames of the Tracking data for Home and Away\n", "def create_home_and_away_dfs(df_tracking):\n", " \n", " \"\"\"\n", " Function to separate the Tracking data into Home and Away DataFrames. Written by Edd Webster / @eddwebster\n", " \"\"\"\n", " \n", " \n", " # Define columns that are found in both DataFrames\n", " lst_cols = ['Frame' ,'Period', 'Time [s]', 'Ball State', 'Ball Owning Team ID', 'ball_x', 'ball_y']\n", " \n", " \n", " # Define columns in Home DataFrame\n", " \n", " ## Create an empty list for home columns\n", " lst_cols_home = []\n", "\n", " ## Extract Home columns from the DataFrame\n", " for col in df_tracking.columns:\n", " if 'Home' in col:\n", " lst_cols_home.append(col)\n", "\n", " \n", " # Define columns in Away DataFrame\n", " \n", " ## Create an empty list for home columns\n", " lst_cols_away = []\n", "\n", " ## Extract Home columns from the DataFrame\n", " for col in df_tracking.columns:\n", " if 'Away' in col:\n", " lst_cols_away.append(col)\n", "\n", "\n", " # Select columns of interest for Home and Away DataFrames\n", " df_tracking_home = df_tracking[lst_cols + lst_cols_home]\n", " df_tracking_away = df_tracking[lst_cols + lst_cols_away]\n", "\n", " \n", " # Return DataFrame\n", " return df_tracking_home, df_tracking_away" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "# Define function to reverse the direction of players\n", "def to_single_playing_direction(home, away):\n", " \n", " '''\n", " Flip coordinates in second half so that each team always shoots in the same direction through the match.\n", " '''\n", " for team in [home, away]:\n", " second_half_idx = team.Period.idxmax(2)\n", " columns = [c for c in team.columns if c[-1].lower() in ['x','y']]\n", " team.loc[second_half_idx:,columns] *= -1\n", " return home, away" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notebook Settings" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "# Display all columns of displayed pandas DataFrames\n", "pd.set_option('display.max_columns', None)\n", "#pd.set_option('display.max_rows', None)\n", "pd.options.mode.chained_assignment = None" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 2. Notebook Brief\n", "This notebook parses and engineers [Second Spectrum](https://www.secondspectrum.com/index.html) using [pandas](http://pandas.pydata.org/) and [`Kloppy`](https://kloppy.pysport.org/), for two Premier League matches featuring Crystal Palace during the 21/22 season. The two datasets provided are for the following matches:\n", "* [27/09/2021: Crystal Palace (1) vs. (1) Brighton & Hove Albion](https://www.bbc.co.uk/sport/football/58620544) (g2210324)\n", "* [03/10/2021: Crystal Palace (2) vs. (2) Leicester City](https://www.bbc.co.uk/sport/football/58667896) (g2210334)\n", "\n", "Once engineered, this dataset will be visualised and analysed in congunction with the corresponding Event data, as part of an opposition analysis piece.\n", "\n", "\n", "**Notebook Conventions**:
\n", "* Variables that refer a `DataFrame` object are prefixed with `df_`.\n", "* Variables that refer to a collection of `DataFrame` objects (e.g., a list, a set or a dict) are prefixed with `dfs_`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 3. Data Sources" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 3.1. Introduction\n", "[Second Spectrum](https://www.secondspectrum.com/index.html) are a football analytics, data provider ... \n", "\n", "![Second Spectrum](../../img/logos/second_spectrum_logo.jpeg)\n", "\n", "The tracking data represents the location of every player on the pitch with a temporal frequency of 25 Hz and the corresponding match time for each tracking frame is specified.\n", "\n", "UPDATE THIS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 3.2. Data Dictionary\n", "The [Second Spectrum](https://www.secondspectrum.com/index.html) Tracking dataset has fourteen features (columns) with the following definitions and data types:\n", "\n", "| Feature | Data type | Definition |\n", "|-----------------|---------------|----------------|\n", "| `Frame` | object | |\n", "| `Period` | object | |\n", "| `Time [s]` | object | |\n", "| `Home_11_x` | object | |\t\n", "| `Home_11_y` | object | |\n", "| `Away_8_x` | object |\t |\n", "| `Away_8_y` | object | |\n", "\n", "UPDATE THIS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 3.3. Import Data\n", "The following cells take the raw meta data (`XML`) and tracking data (`JSONL`) files and read them in as a unified [pandas](https://pandas.pydata.org/) DataFrame, using the custom `read_in_tracking_data` function that I have written (see the functions section at the top of the notebook), powered by [`Kloppy`](https://kloppy.pysport.org/)." ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['../../data/second_spectrum/raw/data/g2210334_SecondSpectrum_Data.csv', '../../data/second_spectrum/raw/data/g2210324_SecondSpectrum_Data.csv']\n" ] } ], "source": [ "# Show files in directory\n", "print(glob.glob(os.path.join(data_dir_second_spectrum, 'raw', 'data/*.csv')))" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "# Read in Tracking data using the custom 'read_in_tracking_data' function, powered by Kloppy\n", "df_tracking_cry_bri = read_in_tracking_data(filename='2210324')\n", "df_tracking_cry_lei = read_in_tracking_data(filename='2210334')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 3.4. Initial Data Handling\n", "To avoid duplication commands and to get an idea of what the output of the Tracking data looks like, this section just goes through tone the two Tracking data files, [Crystal Palace vs. Leicester City](https://www.bbc.co.uk/sport/football/58620544) (g2210334).\n", "\n", "First check the quality of the dataset by looking first and last rows in pandas using the [`head()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.head.html) and [`tail()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.tail.html) methods." ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
period_idtimestampball_stateball_owning_team_idball_xball_y66975_x66975_y66975_d66975_s55494_x55494_y55494_d55494_s80146_x80146_y80146_d80146_s40836_x40836_y40836_d40836_s50471_x50471_y50471_d50471_s199670_x199670_y199670_d199670_s244723_x244723_y244723_d244723_s82403_x82403_y82403_d82403_s209036_x209036_y209036_d209036_s232787_x232787_y232787_d232787_s174874_x174874_y174874_d174874_s101668_x101668_y101668_d101668_s17745_x17745_y17745_d17745_s197469_x197469_y197469_d197469_s218031_x218031_y218031_d218031_s40146_x40146_y40146_d40146_s173515_x173515_y173515_d173515_s201666_x201666_y201666_d201666_s93100_x93100_y93100_d93100_s166989_x166989_y166989_d166989_s219352_x219352_y219352_d219352_s166477_x166477_y166477_d166477_s443661_x443661_y443661_d443661_s225902_x225902_y225902_d225902_s172780_x172780_y172780_d172780_s86417_x86417_y86417_d86417_s51938_x51938_y51938_d51938_s54861_x54861_y54861_d54861_s
010.00dead310.040.090.60-9.08NaNNaN11.4310.22NaNNaN0.219.47NaNNaN42.10-0.19NaNNaN-0.360.35NaNNaN-0.57-20.55NaNNaN7.63-25.09NaNNaN1.22-30.53NaNNaN14.71-12.51NaNNaN0.512.82NaNNaN19.240.54NaNNaN-0.939.31NaNNaN-50.430.12NaNNaN-10.17-19.71NaNNaN-16.67-16.05NaNNaN-13.949.96NaNNaN0.49-10.92NaNNaN-3.1810.89NaNNaN-15.10-0.99NaNNaN-8.980.43NaNNaN-0.99-20.88NaNNaN-14.75-27.43NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
110.04alive310.830.090.56-9.07NaNNaN11.4110.22NaNNaN0.229.47NaNNaN42.11-0.19NaNNaN-0.350.35NaNNaN-0.64-20.47NaNNaN7.62-25.09NaNNaN1.24-30.53NaNNaN14.70-12.52NaNNaN0.502.81NaNNaN19.230.54NaNNaN-0.899.25NaNNaN-50.420.12NaNNaN-10.13-19.70NaNNaN-16.68-16.06NaNNaN-13.949.96NaNNaN0.59-10.86NaNNaN-3.1910.91NaNNaN-15.13-0.99NaNNaN-8.950.44NaNNaN-0.99-20.83NaNNaN-14.75-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
210.08alive311.340.090.53-9.07NaNNaN11.4110.21NaNNaN0.229.46NaNNaN42.11-0.19NaNNaN-0.340.34NaNNaN-0.71-20.40NaNNaN7.62-25.08NaNNaN1.25-30.53NaNNaN14.70-12.53NaNNaN0.492.80NaNNaN19.230.54NaNNaN-0.849.19NaNNaN-50.430.13NaNNaN-10.09-19.69NaNNaN-16.69-16.07NaNNaN-13.939.99NaNNaN0.70-10.80NaNNaN-3.2010.94NaNNaN-15.16-0.99NaNNaN-8.920.44NaNNaN-1.00-20.78NaNNaN-14.76-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
310.12alive312.030.100.50-9.06NaNNaN11.3910.21NaNNaN0.239.45NaNNaN42.11-0.19NaNNaN-0.350.34NaNNaN-0.79-20.31NaNNaN7.60-25.08NaNNaN1.26-30.53NaNNaN14.69-12.54NaNNaN0.472.78NaNNaN19.230.54NaNNaN-0.779.12NaNNaN-50.420.13NaNNaN-10.05-19.67NaNNaN-16.69-16.09NaNNaN-13.9210.02NaNNaN0.80-10.75NaNNaN-3.2210.96NaNNaN-15.16-1.00NaNNaN-8.880.44NaNNaN-1.02-20.73NaNNaN-14.76-27.41NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
410.16alive312.850.110.46-9.06NaNNaN11.4010.19NaNNaN0.259.43NaNNaN42.11-0.19NaNNaN-0.360.33NaNNaN-0.88-20.23NaNNaN7.59-25.07NaNNaN1.27-30.53NaNNaN14.68-12.56NaNNaN0.462.77NaNNaN19.230.54NaNNaN-0.709.04NaNNaN-50.420.13NaNNaN-10.02-19.65NaNNaN-16.70-16.09NaNNaN-13.9310.04NaNNaN0.91-10.69NaNNaN-3.2211.00NaNNaN-15.20-1.01NaNNaN-8.910.45NaNNaN-1.04-20.69NaNNaN-14.78-27.40NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " period_id timestamp ball_state ball_owning_team_id ball_x ball_y \\\n", "0 1 0.00 dead 31 0.04 0.09 \n", "1 1 0.04 alive 31 0.83 0.09 \n", "2 1 0.08 alive 31 1.34 0.09 \n", "3 1 0.12 alive 31 2.03 0.10 \n", "4 1 0.16 alive 31 2.85 0.11 \n", "\n", " 66975_x 66975_y 66975_d 66975_s 55494_x 55494_y 55494_d 55494_s \\\n", "0 0.60 -9.08 NaN NaN 11.43 10.22 NaN NaN \n", "1 0.56 -9.07 NaN NaN 11.41 10.22 NaN NaN \n", "2 0.53 -9.07 NaN NaN 11.41 10.21 NaN NaN \n", "3 0.50 -9.06 NaN NaN 11.39 10.21 NaN NaN \n", "4 0.46 -9.06 NaN NaN 11.40 10.19 NaN NaN \n", "\n", " 80146_x 80146_y 80146_d 80146_s 40836_x 40836_y 40836_d 40836_s \\\n", "0 0.21 9.47 NaN NaN 42.10 -0.19 NaN NaN \n", "1 0.22 9.47 NaN NaN 42.11 -0.19 NaN NaN \n", "2 0.22 9.46 NaN NaN 42.11 -0.19 NaN NaN \n", "3 0.23 9.45 NaN NaN 42.11 -0.19 NaN NaN \n", "4 0.25 9.43 NaN NaN 42.11 -0.19 NaN NaN \n", "\n", " 50471_x 50471_y 50471_d 50471_s 199670_x 199670_y 199670_d 199670_s \\\n", "0 -0.36 0.35 NaN NaN -0.57 -20.55 NaN NaN \n", "1 -0.35 0.35 NaN NaN -0.64 -20.47 NaN NaN \n", "2 -0.34 0.34 NaN NaN -0.71 -20.40 NaN NaN \n", "3 -0.35 0.34 NaN NaN -0.79 -20.31 NaN NaN \n", "4 -0.36 0.33 NaN NaN -0.88 -20.23 NaN NaN \n", "\n", " 244723_x 244723_y 244723_d 244723_s 82403_x 82403_y 82403_d 82403_s \\\n", "0 7.63 -25.09 NaN NaN 1.22 -30.53 NaN NaN \n", "1 7.62 -25.09 NaN NaN 1.24 -30.53 NaN NaN \n", "2 7.62 -25.08 NaN NaN 1.25 -30.53 NaN NaN \n", "3 7.60 -25.08 NaN NaN 1.26 -30.53 NaN NaN \n", "4 7.59 -25.07 NaN NaN 1.27 -30.53 NaN NaN \n", "\n", " 209036_x 209036_y 209036_d 209036_s 232787_x 232787_y 232787_d \\\n", "0 14.71 -12.51 NaN NaN 0.51 2.82 NaN \n", "1 14.70 -12.52 NaN NaN 0.50 2.81 NaN \n", "2 14.70 -12.53 NaN NaN 0.49 2.80 NaN \n", "3 14.69 -12.54 NaN NaN 0.47 2.78 NaN \n", "4 14.68 -12.56 NaN NaN 0.46 2.77 NaN \n", "\n", " 232787_s 174874_x 174874_y 174874_d 174874_s 101668_x 101668_y \\\n", "0 NaN 19.24 0.54 NaN NaN -0.93 9.31 \n", "1 NaN 19.23 0.54 NaN NaN -0.89 9.25 \n", "2 NaN 19.23 0.54 NaN NaN -0.84 9.19 \n", "3 NaN 19.23 0.54 NaN NaN -0.77 9.12 \n", "4 NaN 19.23 0.54 NaN NaN -0.70 9.04 \n", "\n", " 101668_d 101668_s 17745_x 17745_y 17745_d 17745_s 197469_x 197469_y \\\n", "0 NaN NaN -50.43 0.12 NaN NaN -10.17 -19.71 \n", "1 NaN NaN -50.42 0.12 NaN NaN -10.13 -19.70 \n", "2 NaN NaN -50.43 0.13 NaN NaN -10.09 -19.69 \n", "3 NaN NaN -50.42 0.13 NaN NaN -10.05 -19.67 \n", "4 NaN NaN -50.42 0.13 NaN NaN -10.02 -19.65 \n", "\n", " 197469_d 197469_s 218031_x 218031_y 218031_d 218031_s 40146_x \\\n", "0 NaN NaN -16.67 -16.05 NaN NaN -13.94 \n", "1 NaN NaN -16.68 -16.06 NaN NaN -13.94 \n", "2 NaN NaN -16.69 -16.07 NaN NaN -13.93 \n", "3 NaN NaN -16.69 -16.09 NaN NaN -13.92 \n", "4 NaN NaN -16.70 -16.09 NaN NaN -13.93 \n", "\n", " 40146_y 40146_d 40146_s 173515_x 173515_y 173515_d 173515_s \\\n", "0 9.96 NaN NaN 0.49 -10.92 NaN NaN \n", "1 9.96 NaN NaN 0.59 -10.86 NaN NaN \n", "2 9.99 NaN NaN 0.70 -10.80 NaN NaN \n", "3 10.02 NaN NaN 0.80 -10.75 NaN NaN \n", "4 10.04 NaN NaN 0.91 -10.69 NaN NaN \n", "\n", " 201666_x 201666_y 201666_d 201666_s 93100_x 93100_y 93100_d 93100_s \\\n", "0 -3.18 10.89 NaN NaN -15.10 -0.99 NaN NaN \n", "1 -3.19 10.91 NaN NaN -15.13 -0.99 NaN NaN \n", "2 -3.20 10.94 NaN NaN -15.16 -0.99 NaN NaN \n", "3 -3.22 10.96 NaN NaN -15.16 -1.00 NaN NaN \n", "4 -3.22 11.00 NaN NaN -15.20 -1.01 NaN NaN \n", "\n", " 166989_x 166989_y 166989_d 166989_s 219352_x 219352_y 219352_d \\\n", "0 -8.98 0.43 NaN NaN -0.99 -20.88 NaN \n", "1 -8.95 0.44 NaN NaN -0.99 -20.83 NaN \n", "2 -8.92 0.44 NaN NaN -1.00 -20.78 NaN \n", "3 -8.88 0.44 NaN NaN -1.02 -20.73 NaN \n", "4 -8.91 0.45 NaN NaN -1.04 -20.69 NaN \n", "\n", " 219352_s 166477_x 166477_y 166477_d 166477_s 443661_x 443661_y \\\n", "0 NaN -14.75 -27.43 NaN NaN NaN NaN \n", "1 NaN -14.75 -27.42 NaN NaN NaN NaN \n", "2 NaN -14.76 -27.42 NaN NaN NaN NaN \n", "3 NaN -14.76 -27.41 NaN NaN NaN NaN \n", "4 NaN -14.78 -27.40 NaN NaN NaN NaN \n", "\n", " 443661_d 443661_s 225902_x 225902_y 225902_d 225902_s 172780_x \\\n", "0 NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN \n", "\n", " 172780_y 172780_d 172780_s 86417_x 86417_y 86417_d 86417_s 51938_x \\\n", "0 NaN NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN NaN \n", "\n", " 51938_y 51938_d 51938_s 54861_x 54861_y 54861_d 54861_s \n", "0 NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN " ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display the first five rows of the DataFrame, df_tracking_cry_lei\n", "df_tracking_cry_lei.head()" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
period_idtimestampball_stateball_owning_team_idball_xball_y66975_x66975_y66975_d66975_s55494_x55494_y55494_d55494_s80146_x80146_y80146_d80146_s40836_x40836_y40836_d40836_s50471_x50471_y50471_d50471_s199670_x199670_y199670_d199670_s244723_x244723_y244723_d244723_s82403_x82403_y82403_d82403_s209036_x209036_y209036_d209036_s232787_x232787_y232787_d232787_s174874_x174874_y174874_d174874_s101668_x101668_y101668_d101668_s17745_x17745_y17745_d17745_s197469_x197469_y197469_d197469_s218031_x218031_y218031_d218031_s40146_x40146_y40146_d40146_s173515_x173515_y173515_d173515_s201666_x201666_y201666_d201666_s93100_x93100_y93100_d93100_s166989_x166989_y166989_d166989_s219352_x219352_y219352_d219352_s166477_x166477_y166477_d166477_s443661_x443661_y443661_d443661_s225902_x225902_y225902_d225902_s172780_x172780_y172780_d172780_s86417_x86417_y86417_d86417_s51938_x51938_y51938_d51938_s54861_x54861_y54861_d54861_s
14561623003.92dead310.00.0-3.75-18.83NaNNaN-3.06-30.92NaNNaNNaNNaNNaNNaN-37.09-5.20NaNNaN-3.05-3.99NaNNaNNaNNaNNaNNaN-1.018.49NaNNaN6.1613.24NaNNaN-13.54-3.99NaNNaNNaNNaNNaNNaN-19.02-27.61NaNNaN-2.28-26.67NaNNaN41.40-1.46NaNNaNNaNNaNNaNNaN19.16-4.38NaNNaN17.66-23.71NaNNaNNaNNaNNaNNaN-1.41-22.07NaNNaN20.40-14.86NaNNaN7.23-20.32NaNNaNNaNNaNNaNNaN16.146.60NaNNaN3.14-31.79NaNNaN9.04-6.38NaNNaN-2.69-16.54NaNNaN14.74-21.58NaNNaN6.374.74NaNNaN20.38-2.36NaNNaN
14561723003.96dead310.00.0-3.76-18.77NaNNaN-3.07-30.87NaNNaNNaNNaNNaNNaN-37.07-5.24NaNNaN-3.05-3.97NaNNaNNaNNaNNaNNaN-0.988.54NaNNaN6.2013.26NaNNaN-13.55-3.97NaNNaNNaNNaNNaNNaN-19.02-27.58NaNNaN-2.31-26.62NaNNaN41.38-1.46NaNNaNNaNNaNNaNNaN19.14-4.34NaNNaN17.68-23.67NaNNaNNaNNaNNaNNaN-1.36-22.05NaNNaN20.38-14.81NaNNaN7.22-20.26NaNNaNNaNNaNNaNNaN16.176.64NaNNaN3.25-31.75NaNNaN9.04-6.34NaNNaN-2.69-16.50NaNNaN14.74-21.55NaNNaN6.404.78NaNNaN20.36-2.30NaNNaN
14561823004.00dead310.00.0-3.78-18.73NaNNaN-3.09-30.82NaNNaNNaNNaNNaNNaN-37.04-5.27NaNNaN-3.04-3.95NaNNaNNaNNaNNaNNaN-0.958.58NaNNaN6.2313.29NaNNaN-13.56-3.95NaNNaNNaNNaNNaNNaN-19.00-27.55NaNNaN-2.34-26.58NaNNaN41.37-1.45NaNNaNNaNNaNNaNNaN19.12-4.30NaNNaN17.70-23.64NaNNaNNaNNaNNaNNaN-1.32-22.02NaNNaN20.36-14.77NaNNaN7.22-20.21NaNNaNNaNNaNNaNNaN16.196.68NaNNaN3.35-31.71NaNNaN9.04-6.29NaNNaN-2.69-16.45NaNNaN14.75-21.53NaNNaN6.424.82NaNNaN20.34-2.24NaNNaN
14561923004.04dead310.00.0-3.80-18.67NaNNaN-3.10-30.77NaNNaNNaNNaNNaNNaN-37.01-5.31NaNNaN-3.04-3.92NaNNaNNaNNaNNaNNaN-0.928.63NaNNaN6.2613.32NaNNaN-13.57-3.92NaNNaNNaNNaNNaNNaN-18.99-27.51NaNNaN-2.36-26.54NaNNaN41.35-1.44NaNNaNNaNNaNNaNNaN19.09-4.25NaNNaN17.72-23.60NaNNaNNaNNaNNaNNaN-1.27-21.99NaNNaN20.33-14.72NaNNaN7.21-20.15NaNNaNNaNNaNNaNNaN16.216.72NaNNaN3.45-31.67NaNNaN9.03-6.25NaNNaN-2.68-16.41NaNNaN14.75-21.50NaNNaN6.454.86NaNNaN20.31-2.18NaNNaN
14562023004.08dead310.00.0-3.81-18.62NaNNaN-3.12-30.72NaNNaNNaNNaNNaNNaN-36.98-5.34NaNNaN-3.04-3.90NaNNaNNaNNaNNaNNaN-0.908.68NaNNaN6.2913.34NaNNaN-13.58-3.90NaNNaNNaNNaNNaNNaN-18.98-27.48NaNNaN-2.38-26.50NaNNaN41.34-1.43NaNNaNNaNNaNNaNNaN19.07-4.20NaNNaN17.74-23.56NaNNaNNaNNaNNaNNaN-1.23-21.97NaNNaN20.31-14.68NaNNaN7.20-20.10NaNNaNNaNNaNNaNNaN16.236.76NaNNaN3.54-31.63NaNNaN9.03-6.20NaNNaN-2.68-16.36NaNNaN14.76-21.48NaNNaN6.484.90NaNNaN20.29-2.13NaNNaN
\n", "
" ], "text/plain": [ " period_id timestamp ball_state ball_owning_team_id ball_x ball_y \\\n", "145616 2 3003.92 dead 31 0.0 0.0 \n", "145617 2 3003.96 dead 31 0.0 0.0 \n", "145618 2 3004.00 dead 31 0.0 0.0 \n", "145619 2 3004.04 dead 31 0.0 0.0 \n", "145620 2 3004.08 dead 31 0.0 0.0 \n", "\n", " 66975_x 66975_y 66975_d 66975_s 55494_x 55494_y 55494_d \\\n", "145616 -3.75 -18.83 NaN NaN -3.06 -30.92 NaN \n", "145617 -3.76 -18.77 NaN NaN -3.07 -30.87 NaN \n", "145618 -3.78 -18.73 NaN NaN -3.09 -30.82 NaN \n", "145619 -3.80 -18.67 NaN NaN -3.10 -30.77 NaN \n", "145620 -3.81 -18.62 NaN NaN -3.12 -30.72 NaN \n", "\n", " 55494_s 80146_x 80146_y 80146_d 80146_s 40836_x 40836_y \\\n", "145616 NaN NaN NaN NaN NaN -37.09 -5.20 \n", "145617 NaN NaN NaN NaN NaN -37.07 -5.24 \n", "145618 NaN NaN NaN NaN NaN -37.04 -5.27 \n", "145619 NaN NaN NaN NaN NaN -37.01 -5.31 \n", "145620 NaN NaN NaN NaN NaN -36.98 -5.34 \n", "\n", " 40836_d 40836_s 50471_x 50471_y 50471_d 50471_s 199670_x \\\n", "145616 NaN NaN -3.05 -3.99 NaN NaN NaN \n", "145617 NaN NaN -3.05 -3.97 NaN NaN NaN \n", "145618 NaN NaN -3.04 -3.95 NaN NaN NaN \n", "145619 NaN NaN -3.04 -3.92 NaN NaN NaN \n", "145620 NaN NaN -3.04 -3.90 NaN NaN NaN \n", "\n", " 199670_y 199670_d 199670_s 244723_x 244723_y 244723_d 244723_s \\\n", "145616 NaN NaN NaN -1.01 8.49 NaN NaN \n", "145617 NaN NaN NaN -0.98 8.54 NaN NaN \n", "145618 NaN NaN NaN -0.95 8.58 NaN NaN \n", "145619 NaN NaN NaN -0.92 8.63 NaN NaN \n", "145620 NaN NaN NaN -0.90 8.68 NaN NaN \n", "\n", " 82403_x 82403_y 82403_d 82403_s 209036_x 209036_y 209036_d \\\n", "145616 6.16 13.24 NaN NaN -13.54 -3.99 NaN \n", "145617 6.20 13.26 NaN NaN -13.55 -3.97 NaN \n", "145618 6.23 13.29 NaN NaN -13.56 -3.95 NaN \n", "145619 6.26 13.32 NaN NaN -13.57 -3.92 NaN \n", "145620 6.29 13.34 NaN NaN -13.58 -3.90 NaN \n", "\n", " 209036_s 232787_x 232787_y 232787_d 232787_s 174874_x 174874_y \\\n", "145616 NaN NaN NaN NaN NaN -19.02 -27.61 \n", "145617 NaN NaN NaN NaN NaN -19.02 -27.58 \n", "145618 NaN NaN NaN NaN NaN -19.00 -27.55 \n", "145619 NaN NaN NaN NaN NaN -18.99 -27.51 \n", "145620 NaN NaN NaN NaN NaN -18.98 -27.48 \n", "\n", " 174874_d 174874_s 101668_x 101668_y 101668_d 101668_s 17745_x \\\n", "145616 NaN NaN -2.28 -26.67 NaN NaN 41.40 \n", "145617 NaN NaN -2.31 -26.62 NaN NaN 41.38 \n", "145618 NaN NaN -2.34 -26.58 NaN NaN 41.37 \n", "145619 NaN NaN -2.36 -26.54 NaN NaN 41.35 \n", "145620 NaN NaN -2.38 -26.50 NaN NaN 41.34 \n", "\n", " 17745_y 17745_d 17745_s 197469_x 197469_y 197469_d 197469_s \\\n", "145616 -1.46 NaN NaN NaN NaN NaN NaN \n", "145617 -1.46 NaN NaN NaN NaN NaN NaN \n", "145618 -1.45 NaN NaN NaN NaN NaN NaN \n", "145619 -1.44 NaN NaN NaN NaN NaN NaN \n", "145620 -1.43 NaN NaN NaN NaN NaN NaN \n", "\n", " 218031_x 218031_y 218031_d 218031_s 40146_x 40146_y 40146_d \\\n", "145616 19.16 -4.38 NaN NaN 17.66 -23.71 NaN \n", "145617 19.14 -4.34 NaN NaN 17.68 -23.67 NaN \n", "145618 19.12 -4.30 NaN NaN 17.70 -23.64 NaN \n", "145619 19.09 -4.25 NaN NaN 17.72 -23.60 NaN \n", "145620 19.07 -4.20 NaN NaN 17.74 -23.56 NaN \n", "\n", " 40146_s 173515_x 173515_y 173515_d 173515_s 201666_x 201666_y \\\n", "145616 NaN NaN NaN NaN NaN -1.41 -22.07 \n", "145617 NaN NaN NaN NaN NaN -1.36 -22.05 \n", "145618 NaN NaN NaN NaN NaN -1.32 -22.02 \n", "145619 NaN NaN NaN NaN NaN -1.27 -21.99 \n", "145620 NaN NaN NaN NaN NaN -1.23 -21.97 \n", "\n", " 201666_d 201666_s 93100_x 93100_y 93100_d 93100_s 166989_x \\\n", "145616 NaN NaN 20.40 -14.86 NaN NaN 7.23 \n", "145617 NaN NaN 20.38 -14.81 NaN NaN 7.22 \n", "145618 NaN NaN 20.36 -14.77 NaN NaN 7.22 \n", "145619 NaN NaN 20.33 -14.72 NaN NaN 7.21 \n", "145620 NaN NaN 20.31 -14.68 NaN NaN 7.20 \n", "\n", " 166989_y 166989_d 166989_s 219352_x 219352_y 219352_d 219352_s \\\n", "145616 -20.32 NaN NaN NaN NaN NaN NaN \n", "145617 -20.26 NaN NaN NaN NaN NaN NaN \n", "145618 -20.21 NaN NaN NaN NaN NaN NaN \n", "145619 -20.15 NaN NaN NaN NaN NaN NaN \n", "145620 -20.10 NaN NaN NaN NaN NaN NaN \n", "\n", " 166477_x 166477_y 166477_d 166477_s 443661_x 443661_y 443661_d \\\n", "145616 16.14 6.60 NaN NaN 3.14 -31.79 NaN \n", "145617 16.17 6.64 NaN NaN 3.25 -31.75 NaN \n", "145618 16.19 6.68 NaN NaN 3.35 -31.71 NaN \n", "145619 16.21 6.72 NaN NaN 3.45 -31.67 NaN \n", "145620 16.23 6.76 NaN NaN 3.54 -31.63 NaN \n", "\n", " 443661_s 225902_x 225902_y 225902_d 225902_s 172780_x 172780_y \\\n", "145616 NaN 9.04 -6.38 NaN NaN -2.69 -16.54 \n", "145617 NaN 9.04 -6.34 NaN NaN -2.69 -16.50 \n", "145618 NaN 9.04 -6.29 NaN NaN -2.69 -16.45 \n", "145619 NaN 9.03 -6.25 NaN NaN -2.68 -16.41 \n", "145620 NaN 9.03 -6.20 NaN NaN -2.68 -16.36 \n", "\n", " 172780_d 172780_s 86417_x 86417_y 86417_d 86417_s 51938_x \\\n", "145616 NaN NaN 14.74 -21.58 NaN NaN 6.37 \n", "145617 NaN NaN 14.74 -21.55 NaN NaN 6.40 \n", "145618 NaN NaN 14.75 -21.53 NaN NaN 6.42 \n", "145619 NaN NaN 14.75 -21.50 NaN NaN 6.45 \n", "145620 NaN NaN 14.76 -21.48 NaN NaN 6.48 \n", "\n", " 51938_y 51938_d 51938_s 54861_x 54861_y 54861_d 54861_s \n", "145616 4.74 NaN NaN 20.38 -2.36 NaN NaN \n", "145617 4.78 NaN NaN 20.36 -2.30 NaN NaN \n", "145618 4.82 NaN NaN 20.34 -2.24 NaN NaN \n", "145619 4.86 NaN NaN 20.31 -2.18 NaN NaN \n", "145620 4.90 NaN NaN 20.29 -2.13 NaN NaN " ] }, "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display the last five rows of the DataFrame, df_tracking_cry_lei\n", "df_tracking_cry_lei.tail()" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(145621, 118)\n" ] } ], "source": [ "# Print the shape of the DataFrame, df_tracking_cry_lei\n", "print(df_tracking_cry_lei.shape)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The DataFrame has 145,621 rows, which is what we would expected - 25 fps × 60 secs × 90 mins = 135,000 (excluding injury time)." ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['period_id', 'timestamp', 'ball_state', 'ball_owning_team_id', 'ball_x',\n", " 'ball_y', '66975_x', '66975_y', '66975_d', '66975_s',\n", " ...\n", " '86417_d', '86417_s', '51938_x', '51938_y', '51938_d', '51938_s',\n", " '54861_x', '54861_y', '54861_d', '54861_s'],\n", " dtype='object', length=118)\n" ] } ], "source": [ "# Print the column names of the DataFrame, df_tracking_cry_lei\n", "print(df_tracking_cry_lei.columns)" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "period_id int64\n", "timestamp float64\n", "ball_state object\n", "ball_owning_team_id int64\n", "ball_x float64\n", " ... \n", "51938_s float64\n", "54861_x float64\n", "54861_y float64\n", "54861_d float64\n", "54861_s float64\n", "Length: 118, dtype: object" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Data types of the features of the raw DataFrame, df_tracking_cry_lei\n", "df_tracking_cry_lei.dtypes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Full details of these attributes and their data types is discussed further in the [Data Dictionary](section3.2)." ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "period_id int64\n", "timestamp float64\n", "ball_state object\n", "ball_owning_team_id int64\n", "ball_x float64\n", "ball_y float64\n", "66975_x float64\n", "66975_y float64\n", "66975_d float64\n", "66975_s float64\n", "55494_x float64\n", "55494_y float64\n", "55494_d float64\n", "55494_s float64\n", "80146_x float64\n", "80146_y float64\n", "80146_d float64\n", "80146_s float64\n", "40836_x float64\n", "40836_y float64\n", "40836_d float64\n", "40836_s float64\n", "50471_x float64\n", "50471_y float64\n", "50471_d float64\n", "50471_s float64\n", "199670_x float64\n", "199670_y float64\n", "199670_d float64\n", "199670_s float64\n", "244723_x float64\n", "244723_y float64\n", "244723_d float64\n", "244723_s float64\n", "82403_x float64\n", "82403_y float64\n", "82403_d float64\n", "82403_s float64\n", "209036_x float64\n", "209036_y float64\n", "209036_d float64\n", "209036_s float64\n", "232787_x float64\n", "232787_y float64\n", "232787_d float64\n", "232787_s float64\n", "174874_x float64\n", "174874_y float64\n", "174874_d float64\n", "174874_s float64\n", "101668_x float64\n", "101668_y float64\n", "101668_d float64\n", "101668_s float64\n", "17745_x float64\n", "17745_y float64\n", "17745_d float64\n", "17745_s float64\n", "197469_x float64\n", "197469_y float64\n", "197469_d float64\n", "197469_s float64\n", "218031_x float64\n", "218031_y float64\n", "218031_d float64\n", "218031_s float64\n", "40146_x float64\n", "40146_y float64\n", "40146_d float64\n", "40146_s float64\n", "173515_x float64\n", "173515_y float64\n", "173515_d float64\n", "173515_s float64\n", "201666_x float64\n", "201666_y float64\n", "201666_d float64\n", "201666_s float64\n", "93100_x float64\n", "93100_y float64\n", "93100_d float64\n", "93100_s float64\n", "166989_x float64\n", "166989_y float64\n", "166989_d float64\n", "166989_s float64\n", "219352_x float64\n", "219352_y float64\n", "219352_d float64\n", "219352_s float64\n", "166477_x float64\n", "166477_y float64\n", "166477_d float64\n", "166477_s float64\n", "443661_x float64\n", "443661_y float64\n", "443661_d float64\n", "443661_s float64\n", "225902_x float64\n", "225902_y float64\n", "225902_d float64\n", "225902_s float64\n", "172780_x float64\n", "172780_y float64\n", "172780_d float64\n", "172780_s float64\n", "86417_x float64\n", "86417_y float64\n", "86417_d float64\n", "86417_s float64\n", "51938_x float64\n", "51938_y float64\n", "51938_d float64\n", "51938_s float64\n", "54861_x float64\n", "54861_y float64\n", "54861_d float64\n", "54861_s float64\n", "dtype: object\n" ] } ], "source": [ "# Displays all columns\n", "with pd.option_context('display.max_rows', None, 'display.max_columns', None):\n", " print(df_tracking_cry_lei.dtypes)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 145621 entries, 0 to 145620\n", "Columns: 118 entries, period_id to 54861_s\n", "dtypes: float64(115), int64(2), object(1)\n", "memory usage: 131.1+ MB\n" ] } ], "source": [ "# Info for the raw DataFrame, df_tracking_cry_lei\n", "df_tracking_cry_lei.info()" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAABv0AAAGdCAYAAAAxA79RAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYE0lEQVR4nO3df4xlZ13H8c+3bKsGAlEUMaEKjQgGEq7/gCDYqYAWRbPgYvxFWgQi0Ii3AaUS1MakkRjUUSRVKLQQVjFQoP6oog07pZVY8cdi1EhpChSwBQpot6HNSvv4x70bb4fd7p3dmbn9tq9XMrl3znmes8/pnZk/+s45p8YYAQAAAAAAAPo6ZdULAAAAAAAAAE6O6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6LeEqtpXVW+sqmuq6raqGlX1zlWvCwAAAAAAAJJkz6oX0MTrkjwpye1JPpPk8atdDgAAAAAAAPw/V/ot5/wk35XkoUlevuK1AAAAAAAAwD240m8JY4wDR95X1SqXAgAAAAAAAF/DlX4AAAAAAADQnOgHAAAAAAAAzbm95y5aW1sby45dX19Pkkyn06WPf3+as5vrmkwmS48/GQcPHtyV89+N89nKuSQn/vk7l61bW1tbeux9/XfGuUy3NMffsq17oJ5L4m+Z3/8TsxvnkuzOz9n96VzuT3/Lkp39bJzLibs//c44l+mW59zXfs6cy2zObp0LwP3EA/mZXUs3ifuqq666KhdddFHe8Y535PTTT1/1crbDjv48utIPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACa27PqBXRQVXuT7J1/+8j561Or6rL5+1vHGK/e5WUBAAAAAABAEtFvWZMk52zadsb8K0k+lUT0AwAAAAAAYCXc3nMJY4wLxxh1L1+PXvUaAQAAAAAAeOAS/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKC5PateANDPZDLJxsbGluedyBwAAABgNdbW1pYeu76+niSZTqdbGj+ZTLa0JgDg2FzpBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAze1Z9QIAAAB208bGxq7MAQDuO9bW1pYeu76+niSZTqdbnjOZTJaeAwDbzZV+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM3tWfUCAAAA4P5mY2NjV+YA8MCztra29Nj19fUkyXQ63fKcyWSy9BwA7htEPwCA5iaTif+5DAAAtCNgAmwvt/cEAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOZEPwAAAAAAAGhO9AMAAAAAAIDmRD8AAAAAAABoTvQDAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOZEPwAAAAAAAGhO9AMAAAAAAIDmRD8AAAAAAABoTvQDAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOZEPwAAAAAAAGhO9AMAAAAAAIDmRD8AAAAAAABoTvQDAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOZEPwAAAAAAAGhO9AMAAAAAAIDmRD8AAAAAAABoTvQDAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOZEPwAAAAAAAGhO9AMAAAAAAIDmRD8AAAAAAABoTvQDAAAAAACA5kQ/AAAAAAAAaE70AwAAAAAAgOb2rHoBAAAAADywbWxs7Oh4gN2wtra21Lj19fUkyXQ6XfrYR+ZMJpMtrQl4YHGlHwAAAAAAADQn+gEAAAAAAEBzoh8AAAAAAAA0J/oBAAAAAABAc6IfAAAAAAAANCf6AQAAAAAAQHOiHwAAAAAAADQn+gEAAAAAAEBzoh8AAAAAAAA0J/oBAAAAAABAc6IfAAAAAAAANCf6AQAAAAAAQHOiHwAAAAAAADQn+gEAAAAAAEBzoh8AAAAAAAA0J/oBAAAAAABAc6IfAAAAAAAANLdn1QsAgKPZ2NjYlTkAAAAA3NPa2tpS49bX15Mk0+l06WMfmTOZTLa0JuD4XOkHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0JzoBwAAAAAAAM2JfgAAAAAAANCc6AcAAAAAAADNiX4AAAAAAADQnOgHAAAAAAAAzYl+AAAAAAAA0NxS0a+q9lXVG6vqmqq6rapGVb1z2X+kqt46nzOq6juPsv/chf1H+3rZvRz70VV1cVXdWFV3VtUXq+q6qnrVpnEPr6qXVNX7quqGqrqjqv6nqq6tqhdX1df8t6iqU6vqF6vq0qo6WFWH5+t5ybLnDgAAAAAAsBVVdeFRWsktC/trPua/5r1jo6qesMo1s5yd/Gz3LLmG1yV5UpLbk3wmyeO3sPgfTfJz87kPOc7wK5IcPMr2fzzGsX8oyXszO4+/SPKn83/jcUmel+S3F4a/IMnFSW5OciDJTUm+Ncnzk1yS5DlV9YIxxliY8+Ak6/P3n0tyS5LTj3MOAAAAAAAAJ+tjSdYWvr9r4f0vJ3lVknPn434tyd9W1ePGGId2a4GcsB35bJeNfudnFvtuSHJmZtHsuKrqW5K8JbMY98j53Hvz/jHGZUse+4wk70nyxSTPGmNcv2n/qZumXJ/kx5L85Rjj7oVxr03yD0l+PLMAePnCnK8k+eEkB8cYN1fVhUl+fZn1AQAAAAAAnISvjjFu2byxqirJNMnrxxiXz7edk+TzSX46yR/t5iJ3yuHDh3P11VcnSS6//PK84hWvyGmnnbbiVW2bHflsl7q95xjjwBjj45uuglvGm+ev521x3jIuzOyqvpdvDn5JMsb4303ff3CM8eeLwW++/ZYkfzj/dm3TvsNjjL8aY9y8nQsHAAAAAAA4jjOq6rNV9Ymqetf8YqgkeUxmF1r9zZGBY4w7knwoydNWsM5td/jw4ezbty/XXnttkuSKK67Ivn37cvjw4RWvbNvsyGe7VPQ7EVV1bpK9SV42xvjiktMmVTWtqguq6oVV9ahjHPvUJPsyK5tXVtWTq+r8qvqlqnpuVW019R4JhF/d4jwAAAAAAIDtdl1mt3d8TpKXZhaCPlxVD5+/T2aPJVv0uYV9re3fvz+HDt3zTpaHDh3K/v37V7SibbVjn21t9eK9qlrL7Pae+8cYP3uMMd+R5F+T/NkY44XzbRuZ3d7zsWOMGzaNPzfJpUc51F2ZPW9vOsa4c2H89yT55yQfTHJrkp/YNO+mJPvGGB9Z4nz2JPmXJE9McvYY4wP3MvbCzG7v+dIxxiXHOzYAAAAAAMDJqqqHJLkxyeuT/H2Sv0vy7WOMTy+MuTTJt40xzl7NKrfPWWeddVWSZx5l11UHDhx49m6vZydt52e77DP9trK4U5K8PcntSV655LRPJPmFzC5X/EyShyV5epLfTPLzSR6a2b1Kj3jE/PXMJHckeXGS92d2u8/zMnvI4ZVV9d1jjFuP82+/PrPgd+W9BT8AAAAAAIBVGGPcXlX/nuSxmfWQZHbl16cXhj0iX3uFWEsHDhx41qrXsFu287Pdidt7np9ZjHvpGOPLy0wYY1w9xviDMcb1Y4yvjDFuHmO8O8lZSb6c5Keq6kkLUx608PorY4y3jTG+NMa4aYzxmiTvTfLNmV0WeUxV9cokr0ryn0leuJWTBAAAAAAA2A1V9fVJHp/k5swupLolybM37X9Gkg+vZIGcsO38bLc1+lXVY5NclOTSMcaVJ3u8+aWLR47z/Qu7FmPi+44y9ci2Jx/r2FV1XpLfS/IfSc4aY3zpJJYKAAAAAACwLarqDVV1ZlU9pqqekuQ9SR6c5O1j9ty29SQXVNXzq+qJSS7L7A6Mf7yqNbOcnfxst/v2nk9I8nVJXlRVLzrGmI9XVZI8b4zx/iWO+YX564MXtn1s4f1/H2XOkSj4DUc7YFVNk/xukn9L8swxxueXWAcAAAAAAMBueFSSP8nsroZfyOxZb987xvjUfP9vZdZA3pTkG5Ncl+QHxxiHVrBWtmbHPtvtjn6fTPLWY+z7kczuQfruJLfNxy7jKfPXG49sGGN8qaoOJplk9jy+6zbNeeLCeu6hql6T2XP8DiZ59hLP/AMAAAAAANg1Y4yfPM7+keTC+ReN7ORnu63Rb4xxMMlLjravqjYyi36vHWPcsGnfM8YY12zaVkkuSPLUJLcm+etNh3xTkrckuaiqnjvGuHM+71GZPVcwSd616Zi/muQ3kvxTZlXULT0BAAAAAABob6noV1V7k+ydf/vI+etTq+qy+ftbxxivPol1fKiqrk/ykSSfTfKwJN+X2RV7X0nyM2OM2zbNeVtmVw/uTfLRqvpAZrcA3Zvkm5L8/hhjY+Eczsks+N2V5Jokr5zfZnTRJ8cYly1uqKoLMnuAYjK7sjCZ3b706fP3144xLtnqCQMAAAAAAMB2WfZKv0mSczZtO2P+lSSfSnIy0e8NSZ6c5AcyC3Z3J7kps6v5fmeMcePmCWOMu6vqBUnOS/KizK4wvDvJR5NcPMZ456Ypj5m/PijJ9BjruDqzByIuOjvJmZu2PW3+dYToBwAAAAAAwMrU7NagAAAAAAAAQFenrHoBAAAAAAAAwMkR/QAAAAAAAKA50Q8AAAAAAACaE/0AAAAAAACgOdEPAAAAAAAAmhP9AAAAAAAAoDnRDwAAAAAAAJoT/QAAAAAAAKA50Q8AAAAAAACa+z+o9qEBX04H+gAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "# Plot visualisation of the missing values for each feature of the raw DataFrame, df_tracking_cry_lei\n", "msno.matrix(df_tracking_cry_lei, figsize = (30, 7))" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "66975_d 145621\n", "66975_s 145621\n", "55494_d 145621\n", "55494_s 145621\n", "80146_x 63487\n", " ... \n", "51938_s 145621\n", "54861_x 128694\n", "54861_y 128694\n", "54861_d 145621\n", "54861_s 145621\n", "Length: 80, dtype: int64" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Counts of missing values\n", "null_value_stats = df_tracking_cry_lei.isnull().sum(axis=0)\n", "null_value_stats[null_value_stats != 0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 4. Data Engineering\n", "The next step is to wrangle the dataset to into a format that’s suitable for analysis.\n", "\n", "This section is broken down into the following subsections:\n", "\n", "4.1. [Reset Index](#section4.1)
\n", "4.2. [Rename Columns](#section4.2)
\n", "4.3. [Rename Player Columns Using Metadata](#section4.3)
\n", "4.4. [Separate Home and Away DataFrames](#section4.4)
\n", "4.5. [Calculate Player Velocities](#section4.5)
\n", "4.6. [Reverse direction of players](#section4.6)
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.1. Reset Index\n", "Reset index, the existing index will not be dropped and will be used to identify the frame number." ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "# Reset index, the existing index will be used for the frame number\n", "df_tracking_cry_bri = df_tracking_cry_bri.reset_index(drop=False)\n", "df_tracking_cry_lei = df_tracking_cry_lei.reset_index(drop=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.2. Rename Columns\n", "To work with [Laurie Shaw](https://twitter.com/EightyFivePoint)'s Metrica Sports Tracking data libraries, [`LaurieOnTracking`](https://github.com/Friends-of-Tracking-Data-FoTD/LaurieOnTracking), the data needs to be engineered to match the Metrica schema, which is the following:\n", "\n", "| Feature | Data type | Definition |\n", "|-------------------------------------------|---------------|----------------|\n", "| `Frame` | int64 | |\n", "| `Period` | int64 | |\n", "| `Time [s]` | float64 | |\n", "| `Home/Away_No._x` (repeated 14 times) | float64 | |\t\n", "| `Home/Away_No._y` (repeated 14 times) | float64 | |\n", "| `ball_x` | float64 |\t |\n", "| `ball_y` | float64 | |\n", "\n", "To learn more about the Metrica Sports schema, see the official documentation [[link](https://github.com/metrica-sports/sample-data/blob/master/documentation/events-definitions.pdf)]." ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "# Rename columns\n", "df_tracking_cry_lei = df_tracking_cry_lei.rename(columns={'period_id': 'Period',\n", " 'timestamp': 'Time [s]',\n", " 'ball_state': 'Ball State',\n", " 'ball_owning_team_id': 'Ball Owning Team ID',\n", " 'index': 'Frame'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [], "source": [ "# Rename columns\n", "df_tracking_cry_bri = df_tracking_cry_bri.rename(columns={'period_id': 'Period',\n", " 'timestamp': 'Time [s]',\n", " 'ball_state': 'Ball State',\n", " 'ball_owning_team_id': 'Ball Owning Team ID',\n", " 'index': 'Frame'\n", " }\n", " )" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FramePeriodTime [s]Ball StateBall Owning Team IDball_xball_y50471_x50471_y50471_d50471_s66975_x66975_y66975_d66975_s199670_x199670_y199670_d199670_s80146_x80146_y80146_d80146_s174874_x174874_y174874_d174874_s244723_x244723_y244723_d244723_s232787_x232787_y232787_d232787_s55494_x55494_y55494_d55494_s82403_x82403_y82403_d82403_s209036_x209036_y209036_d209036_s40836_x40836_y40836_d40836_s116216_x116216_y116216_d116216_s115382_x115382_y115382_d115382_s179268_x179268_y179268_d179268_s60307_x60307_y60307_d60307_s111478_x111478_y111478_d111478_s61933_x61933_y61933_d61933_s39155_x39155_y39155_d39155_s83299_x83299_y83299_d83299_s50175_x50175_y50175_d50175_s215059_x215059_y215059_d215059_s78916_x78916_y78916_d78916_s235382_x235382_y235382_d235382_s243505_x243505_y243505_d243505_s54861_x54861_y54861_d54861_s55037_x55037_y55037_d55037_s233425_x233425_y233425_d233425_s86417_x86417_y86417_d86417_s
0010.00dead31-0.060.02-9.412.46NaNNaN-7.85-6.82NaNNaN0.119.07NaNNaN-1.60-28.63NaNNaN-19.66-13.13NaNNaN-19.066.63NaNNaN-2.85-14.11NaNNaN-15.20-25.35NaNNaN-2.9319.45NaNNaN-19.64-3.11NaNNaN-45.54-0.09NaNNaN-0.03-10.30NaNNaN-0.260.34NaNNaN14.59-19.99NaNNaN7.076.07NaNNaN3.7920.08NaNNaN14.578.56NaNNaN7.25-7.72NaNNaN21.50-6.01NaNNaN0.35-17.21NaNNaN41.03-0.00NaNNaN0.24-29.41NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1110.04alive361.11-0.36-9.432.46NaNNaN-7.85-6.84NaNNaN0.159.03NaNNaN-1.59-28.66NaNNaN-19.65-13.14NaNNaN-19.066.62NaNNaN-2.84-14.08NaNNaN-15.21-25.35NaNNaN-2.8919.46NaNNaN-19.63-3.10NaNNaN-45.53-0.09NaNNaN-0.09-10.30NaNNaN-0.270.35NaNNaN14.57-20.00NaNNaN7.076.07NaNNaN3.7820.07NaNNaN14.538.57NaNNaN7.25-7.72NaNNaN21.49-6.01NaNNaN0.35-17.20NaNNaN41.01-0.01NaNNaN0.20-29.44NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2210.08alive361.57-0.52-9.442.46NaNNaN-7.86-6.86NaNNaN0.198.99NaNNaN-1.57-28.68NaNNaN-19.64-13.14NaNNaN-19.076.62NaNNaN-2.84-14.05NaNNaN-15.23-25.36NaNNaN-2.8519.47NaNNaN-19.63-3.10NaNNaN-45.52-0.09NaNNaN-0.16-10.29NaNNaN-0.280.33NaNNaN14.55-20.00NaNNaN7.076.08NaNNaN3.7720.06NaNNaN14.508.58NaNNaN7.25-7.71NaNNaN21.48-6.00NaNNaN0.34-17.20NaNNaN40.99-0.01NaNNaN0.16-29.47NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3310.12alive362.23-0.73-9.452.46NaNNaN-7.87-6.88NaNNaN0.248.93NaNNaN-1.56-28.70NaNNaN-19.62-13.14NaNNaN-19.076.62NaNNaN-2.83-14.02NaNNaN-15.25-25.36NaNNaN-2.8019.48NaNNaN-19.62-3.10NaNNaN-45.50-0.10NaNNaN-0.24-10.29NaNNaN-0.290.32NaNNaN14.53-20.01NaNNaN7.076.09NaNNaN3.7720.06NaNNaN14.468.59NaNNaN7.25-7.71NaNNaN21.47-5.98NaNNaN0.33-17.19NaNNaN40.98-0.01NaNNaN0.10-29.50NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4410.16alive362.90-0.94-9.472.46NaNNaN-7.87-6.90NaNNaN0.298.87NaNNaN-1.55-28.73NaNNaN-19.61-13.14NaNNaN-19.076.62NaNNaN-2.83-14.00NaNNaN-15.28-25.36NaNNaN-2.7619.49NaNNaN-19.62-3.11NaNNaN-45.49-0.10NaNNaN-0.32-10.29NaNNaN-0.300.32NaNNaN14.51-20.01NaNNaN7.076.09NaNNaN3.7620.05NaNNaN14.438.59NaNNaN7.24-7.71NaNNaN21.47-5.97NaNNaN0.32-17.18NaNNaN40.96-0.01NaNNaN0.04-29.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Frame Period Time [s] Ball State Ball Owning Team ID ball_x ball_y \\\n", "0 0 1 0.00 dead 31 -0.06 0.02 \n", "1 1 1 0.04 alive 36 1.11 -0.36 \n", "2 2 1 0.08 alive 36 1.57 -0.52 \n", "3 3 1 0.12 alive 36 2.23 -0.73 \n", "4 4 1 0.16 alive 36 2.90 -0.94 \n", "\n", " 50471_x 50471_y 50471_d 50471_s 66975_x 66975_y 66975_d 66975_s \\\n", "0 -9.41 2.46 NaN NaN -7.85 -6.82 NaN NaN \n", "1 -9.43 2.46 NaN NaN -7.85 -6.84 NaN NaN \n", "2 -9.44 2.46 NaN NaN -7.86 -6.86 NaN NaN \n", "3 -9.45 2.46 NaN NaN -7.87 -6.88 NaN NaN \n", "4 -9.47 2.46 NaN NaN -7.87 -6.90 NaN NaN \n", "\n", " 199670_x 199670_y 199670_d 199670_s 80146_x 80146_y 80146_d 80146_s \\\n", "0 0.11 9.07 NaN NaN -1.60 -28.63 NaN NaN \n", "1 0.15 9.03 NaN NaN -1.59 -28.66 NaN NaN \n", "2 0.19 8.99 NaN NaN -1.57 -28.68 NaN NaN \n", "3 0.24 8.93 NaN NaN -1.56 -28.70 NaN NaN \n", "4 0.29 8.87 NaN NaN -1.55 -28.73 NaN NaN \n", "\n", " 174874_x 174874_y 174874_d 174874_s 244723_x 244723_y 244723_d \\\n", "0 -19.66 -13.13 NaN NaN -19.06 6.63 NaN \n", "1 -19.65 -13.14 NaN NaN -19.06 6.62 NaN \n", "2 -19.64 -13.14 NaN NaN -19.07 6.62 NaN \n", "3 -19.62 -13.14 NaN NaN -19.07 6.62 NaN \n", "4 -19.61 -13.14 NaN NaN -19.07 6.62 NaN \n", "\n", " 244723_s 232787_x 232787_y 232787_d 232787_s 55494_x 55494_y \\\n", "0 NaN -2.85 -14.11 NaN NaN -15.20 -25.35 \n", "1 NaN -2.84 -14.08 NaN NaN -15.21 -25.35 \n", "2 NaN -2.84 -14.05 NaN NaN -15.23 -25.36 \n", "3 NaN -2.83 -14.02 NaN NaN -15.25 -25.36 \n", "4 NaN -2.83 -14.00 NaN NaN -15.28 -25.36 \n", "\n", " 55494_d 55494_s 82403_x 82403_y 82403_d 82403_s 209036_x 209036_y \\\n", "0 NaN NaN -2.93 19.45 NaN NaN -19.64 -3.11 \n", "1 NaN NaN -2.89 19.46 NaN NaN -19.63 -3.10 \n", "2 NaN NaN -2.85 19.47 NaN NaN -19.63 -3.10 \n", "3 NaN NaN -2.80 19.48 NaN NaN -19.62 -3.10 \n", "4 NaN NaN -2.76 19.49 NaN NaN -19.62 -3.11 \n", "\n", " 209036_d 209036_s 40836_x 40836_y 40836_d 40836_s 116216_x 116216_y \\\n", "0 NaN NaN -45.54 -0.09 NaN NaN -0.03 -10.30 \n", "1 NaN NaN -45.53 -0.09 NaN NaN -0.09 -10.30 \n", "2 NaN NaN -45.52 -0.09 NaN NaN -0.16 -10.29 \n", "3 NaN NaN -45.50 -0.10 NaN NaN -0.24 -10.29 \n", "4 NaN NaN -45.49 -0.10 NaN NaN -0.32 -10.29 \n", "\n", " 116216_d 116216_s 115382_x 115382_y 115382_d 115382_s 179268_x \\\n", "0 NaN NaN -0.26 0.34 NaN NaN 14.59 \n", "1 NaN NaN -0.27 0.35 NaN NaN 14.57 \n", "2 NaN NaN -0.28 0.33 NaN NaN 14.55 \n", "3 NaN NaN -0.29 0.32 NaN NaN 14.53 \n", "4 NaN NaN -0.30 0.32 NaN NaN 14.51 \n", "\n", " 179268_y 179268_d 179268_s 60307_x 60307_y 60307_d 60307_s 111478_x \\\n", "0 -19.99 NaN NaN 7.07 6.07 NaN NaN 3.79 \n", "1 -20.00 NaN NaN 7.07 6.07 NaN NaN 3.78 \n", "2 -20.00 NaN NaN 7.07 6.08 NaN NaN 3.77 \n", "3 -20.01 NaN NaN 7.07 6.09 NaN NaN 3.77 \n", "4 -20.01 NaN NaN 7.07 6.09 NaN NaN 3.76 \n", "\n", " 111478_y 111478_d 111478_s 61933_x 61933_y 61933_d 61933_s 39155_x \\\n", "0 20.08 NaN NaN 14.57 8.56 NaN NaN 7.25 \n", "1 20.07 NaN NaN 14.53 8.57 NaN NaN 7.25 \n", "2 20.06 NaN NaN 14.50 8.58 NaN NaN 7.25 \n", "3 20.06 NaN NaN 14.46 8.59 NaN NaN 7.25 \n", "4 20.05 NaN NaN 14.43 8.59 NaN NaN 7.24 \n", "\n", " 39155_y 39155_d 39155_s 83299_x 83299_y 83299_d 83299_s 50175_x \\\n", "0 -7.72 NaN NaN 21.50 -6.01 NaN NaN 0.35 \n", "1 -7.72 NaN NaN 21.49 -6.01 NaN NaN 0.35 \n", "2 -7.71 NaN NaN 21.48 -6.00 NaN NaN 0.34 \n", "3 -7.71 NaN NaN 21.47 -5.98 NaN NaN 0.33 \n", "4 -7.71 NaN NaN 21.47 -5.97 NaN NaN 0.32 \n", "\n", " 50175_y 50175_d 50175_s 215059_x 215059_y 215059_d 215059_s 78916_x \\\n", "0 -17.21 NaN NaN 41.03 -0.00 NaN NaN 0.24 \n", "1 -17.20 NaN NaN 41.01 -0.01 NaN NaN 0.20 \n", "2 -17.20 NaN NaN 40.99 -0.01 NaN NaN 0.16 \n", "3 -17.19 NaN NaN 40.98 -0.01 NaN NaN 0.10 \n", "4 -17.18 NaN NaN 40.96 -0.01 NaN NaN 0.04 \n", "\n", " 78916_y 78916_d 78916_s 235382_x 235382_y 235382_d 235382_s \\\n", "0 -29.41 NaN NaN NaN NaN NaN NaN \n", "1 -29.44 NaN NaN NaN NaN NaN NaN \n", "2 -29.47 NaN NaN NaN NaN NaN NaN \n", "3 -29.50 NaN NaN NaN NaN NaN NaN \n", "4 -29.54 NaN NaN NaN NaN NaN NaN \n", "\n", " 243505_x 243505_y 243505_d 243505_s 54861_x 54861_y 54861_d 54861_s \\\n", "0 NaN NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN NaN \n", "\n", " 55037_x 55037_y 55037_d 55037_s 233425_x 233425_y 233425_d 233425_s \\\n", "0 NaN NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN NaN \n", "\n", " 86417_x 86417_y 86417_d 86417_s \n", "0 NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN " ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display DataFrame\n", "df_tracking_cry_bri.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.3. Rename Player Columns Using Metadata\n", "For compatibility with [Laurie Shaw](https://twitter.com/EightyFivePoint)'s Metrica Sports Tracking data library [`LaurieOnTracking`](https://github.com/Friends-of-Tracking-Data-FoTD/LaurieOnTracking), the column of each player is given a `Home_` or `Away_` prefix." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### a) Crystal Palace (2) vs. (2) Leicester City (f2210334)" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [], "source": [ "# Read in the Meta data for the corresponding Tracking data\n", "\n", "## Define the file name\n", "file_name = 'g2210334'\n", "\n", "## Read in the Meta data\n", "df_meta_cry_lei = pd.read_csv(os.path.join(data_dir_second_spectrum, 'raw', 'metadata', f'{file_name}_SecondSpectrum_Metadata_Players.csv'))" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "## Prepare DataFrame to create dictionary\n", "\n", "## Convert data types\n", "df_meta_cry_lei['optaId'] = df_meta_cry_lei['optaId'].astype(int)\n", "df_meta_cry_lei['name'] = df_meta_cry_lei['name'].astype(str)\n", "\n", "## Create a dictionary of Qualifier IDs and Qualifier Names from the reference dataset\n", "dict_home_away_players = dict(zip(df_meta_cry_lei['optaId'], df_meta_cry_lei['HA']))" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{86417: 'Home',\n", " 54861: 'Home',\n", " 105666: 'Home',\n", " 66975: 'Home',\n", " 108413: 'Home',\n", " 443661: 'Home',\n", " 244723: 'Home',\n", " 80146: 'Home',\n", " 209036: 'Home',\n", " 40836: 'Home',\n", " 50471: 'Home',\n", " 174874: 'Home',\n", " 55494: 'Home',\n", " 55037: 'Home',\n", " 49413: 'Home',\n", " 232787: 'Home',\n", " 82403: 'Home',\n", " 199670: 'Home',\n", " 58786: 'Home',\n", " 57328: 'Home',\n", " 245419: 'Away',\n", " 166477: 'Away',\n", " 219352: 'Away',\n", " 166989: 'Away',\n", " 173515: 'Away',\n", " 215413: 'Away',\n", " 111931: 'Away',\n", " 218031: 'Away',\n", " 168580: 'Away',\n", " 51938: 'Away',\n", " 95463: 'Away',\n", " 101668: 'Away',\n", " 155569: 'Away',\n", " 172780: 'Away',\n", " 17745: 'Away',\n", " 197469: 'Away',\n", " 93100: 'Away',\n", " 201666: 'Away',\n", " 225902: 'Away',\n", " 40146: 'Away'}" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict_home_away_players" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "# Map the values to the data (current a hard coded way, will replace with a loop shortly)\n", "dict_home_away_players_cry_lei = {'86417_x': 'Home_15_x',\n", " '54861_x': 'Home_20_x',\n", " '105666_x': 'Home_1_x',\n", " '66975_x': 'Home_4_x',\n", " '108413_x': 'Home_12_x',\n", " '443661_x': 'Home_7_x',\n", " '244723_x': 'Home_3_x',\n", " '80146_x': 'Home_9_x',\n", " '209036_x': 'Home_6_x',\n", " '40836_x': 'Home_13_x',\n", " '50471_x': 'Home_18_x',\n", " '174874_x': 'Home_16_x',\n", " '55494_x': 'Home_2_x',\n", " '55037_x': 'Home_8_x',\n", " '49413_x': 'Home_5_x',\n", " '232787_x': 'Home_23_x',\n", " '82403_x': 'Home_11_x',\n", " '199670_x': 'Home_22_x',\n", " '58786_x': 'Home_34_x',\n", " '57328_x': 'Home_17_x',\n", "\n", " '86417_y': 'Home_15_y',\n", " '54861_y': 'Home_20_y',\n", " '105666_y': 'Home_1_y',\n", " '66975_y': 'Home_4_y',\n", " '108413_y': 'Home_12_y',\n", " '443661_y': 'Home_7_y',\n", " '244723_y': 'Home_3_y',\n", " '80146_y': 'Home_9_y',\n", " '209036_y': 'Home_6_y',\n", " '40836_y': 'Home_13_y',\n", " '50471_y': 'Home_18_y',\n", " '174874_y': 'Home_16_y',\n", " '55494_y': 'Home_2_y',\n", " '55037_y': 'Home_8_y',\n", " '49413_y': 'Home_5_y',\n", " '232787_y': 'Home_23_y',\n", " '82403_y': 'Home_11_y',\n", " '199670_y': 'Home_22_y',\n", " '58786_y': 'Home_34_y',\n", " '57328_y': 'Home_17_y',\n", "\n", " '86417_d': 'Home_15_d',\n", " '54861_d': 'Home_20_d',\n", " '105666_d': 'Home_1_d',\n", " '66975_d': 'Home_4_d',\n", " '108413_d': 'Home_12_d',\n", " '443661_d': 'Home_7_d',\n", " '244723_d': 'Home_3_d',\n", " '80146_d': 'Home_9_d',\n", " '209036_d': 'Home_6_d',\n", " '40836_d': 'Home_13_d',\n", " '50471_d': 'Home_18_d',\n", " '174874_d': 'Home_16_d',\n", " '55494_d': 'Home_2_d',\n", " '55037_d': 'Home_8_d',\n", " '49413_d': 'Home_5_d',\n", " '232787_d': 'Home_23_d',\n", " '82403_d': 'Home_11_d',\n", " '199670_d': 'Home_22_d',\n", " '58786_d': 'Home_34_d',\n", " '57328_d': 'Home_17_d',\n", "\n", " '86417_s': 'Home_15_s',\n", " '54861_s': 'Home_20_s',\n", " '105666_s': 'Home_1_s',\n", " '66975_s': 'Home_4_s',\n", " '108413_s': 'Home_12_s',\n", " '443661_s': 'Home_7_s',\n", " '244723_s': 'Home_3_s',\n", " '80146_s': 'Home_9_s',\n", " '209036_s': 'Home_6_s',\n", " '40836_s': 'Home_13_s',\n", " '50471_s': 'Home_18_s',\n", " '174874_s': 'Home_16_s',\n", " '55494_s': 'Home_2_s',\n", " '55037_s': 'Home_8_s',\n", " '49413_s': 'Home_5_s',\n", " '232787_s': 'Home_23_s',\n", " '82403_s': 'Home_11_s',\n", " '199670_s': 'Home_22_s',\n", " '58786_s': 'Home_34_s',\n", " '57328_s': 'Home_17_s',\n", "\n", " '245419_x': 'Away_29_x',\n", " '166477_x': 'Away_27_x',\n", " '219352_x': 'Away_37_x',\n", " '166989_x': 'Away_8_x',\n", " '173515_x': 'Away_14_x',\n", " '215413_x': 'Away_22_x',\n", " '111931_x': 'Away_21_x',\n", " '218031_x': 'Away_4_x',\n", " '168580_x': 'Away_17_x',\n", " '51938_x': 'Away_11_x',\n", " '95463_x': 'Away_12_x',\n", " '101668_x': 'Away_9_x',\n", " '155569_x': 'Away_18_x',\n", " '172780_x': 'Away_10_x',\n", " '17745_x': 'Away_1_x',\n", " '197469_x': 'Away_20_x',\n", " '93100_x': 'Away_23_x',\n", " '201666_x': 'Away_7_x',\n", " '225902_x': 'Away_42_x',\n", " '40146_x': 'Away_5_x',\n", " \n", " '245419_y': 'Away_29_y',\n", " '166477_y': 'Away_27_y',\n", " '219352_y': 'Away_37_y',\n", " '166989_y': 'Away_8_y',\n", " '173515_y': 'Away_14_y',\n", " '215413_y': 'Away_22_y',\n", " '111931_y': 'Away_21_y',\n", " '218031_y': 'Away_4_y',\n", " '168580_y': 'Away_17_y',\n", " '51938_y': 'Away_11_y',\n", " '95463_y': 'Away_12_y',\n", " '101668_y': 'Away_9_y',\n", " '155569_y': 'Away_18_y',\n", " '172780_y': 'Away_10_y',\n", " '17745_y': 'Away_1_y',\n", " '197469_y': 'Away_20_y',\n", " '93100_y': 'Away_23_y',\n", " '201666_y': 'Away_7_y',\n", " '225902_y': 'Away_42_y',\n", " '40146_y': 'Away_5_y',\n", "\n", " '245419_d': 'Away_29_d',\n", " '166477_d': 'Away_27_d',\n", " '219352_d': 'Away_37_d',\n", " '166989_d': 'Away_8_d',\n", " '173515_d': 'Away_14_d',\n", " '215413_d': 'Away_22_d',\n", " '111931_d': 'Away_21_d',\n", " '218031_d': 'Away_4_d',\n", " '168580_d': 'Away_17_d',\n", " '51938_d': 'Away_11_d',\n", " '95463_d': 'Away_12_d',\n", " '101668_d': 'Away_9_d',\n", " '155569_d': 'Away_18_d',\n", " '172780_d': 'Away_10_d',\n", " '17745_d': 'Away_1_d',\n", " '197469_d': 'Away_20_d',\n", " '93100_d': 'Away_23_d',\n", " '201666_d': 'Away_7_d',\n", " '225902_d': 'Away_42_d',\n", " '40146_d': 'Away_5_d',\n", " \n", " '245419_s': 'Away_29_s',\n", " '166477_s': 'Away_27_s',\n", " '219352_s': 'Away_37_s',\n", " '166989_s': 'Away_8_s',\n", " '173515_s': 'Away_14_s',\n", " '215413_s': 'Away_22_s',\n", " '111931_s': 'Away_21_s',\n", " '218031_s': 'Away_4_s',\n", " '168580_s': 'Away_17_s',\n", " '51938_s': 'Away_11_s',\n", " '95463_s': 'Away_12_s',\n", " '101668_s': 'Away_9_s',\n", " '155569_s': 'Away_18_s',\n", " '172780_s': 'Away_10_s',\n", " '17745_s': 'Away_1_s',\n", " '197469_s': 'Away_20_s',\n", " '93100_s': 'Away_23_s',\n", " '201666_s': 'Away_7_s',\n", " '225902_s': 'Away_42_s',\n", " '40146_s': 'Away_5_s'\n", " }" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "## Map Qualifier Names to Qualifier IDs\n", "df_tracking_cry_lei = df_tracking_cry_lei.rename(columns=dict_home_away_players_cry_lei)" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Frame', 'Period', 'Time [s]', 'Ball State', 'Ball Owning Team ID',\n", " 'ball_x', 'ball_y', 'Home_4_x', 'Home_4_y', 'Home_4_d',\n", " ...\n", " 'Home_15_d', 'Home_15_s', 'Away_11_x', 'Away_11_y', 'Away_11_d',\n", " 'Away_11_s', 'Home_20_x', 'Home_20_y', 'Home_20_d', 'Home_20_s'],\n", " dtype='object', length=119)" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## Display columns\n", "df_tracking_cry_lei.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### b) Crystal Palace (1) vs. (1) Brighton & Hove Albion (f2210324)" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "# Read in the Meta data for the corresponding Tracking data\n", "\n", "## Define the file name\n", "file_name = 'g2210324'\n", "\n", "## Read in the Meta data\n", "df_meta_cry_bri = pd.read_csv(os.path.join(data_dir_second_spectrum, 'raw', 'metadata', f'{file_name}_SecondSpectrum_Metadata_Players.csv'))" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "## Prepare DataFrame to create dictionary\n", "\n", "## Convert data types\n", "df_meta_cry_bri['optaId'] = df_meta_cry_bri['optaId'].astype(int)\n", "df_meta_cry_bri['name'] = df_meta_cry_bri['name'].astype(str)\n", "\n", "## Create a dictionary of Qualifier IDs and Qualifier Names from the reference dataset\n", "dict_home_away_players = dict(zip(df_meta_cry_bri['optaId'], df_meta_cry_bri['HA']))" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{55037: 'Home',\n", " 50471: 'Home',\n", " 80146: 'Home',\n", " 82403: 'Home',\n", " 108413: 'Home',\n", " 199670: 'Home',\n", " 232787: 'Home',\n", " 174874: 'Home',\n", " 244723: 'Home',\n", " 66975: 'Home',\n", " 55494: 'Home',\n", " 209036: 'Home',\n", " 54861: 'Home',\n", " 86417: 'Home',\n", " 105666: 'Home',\n", " 231747: 'Home',\n", " 40836: 'Home',\n", " 58786: 'Home',\n", " 443661: 'Home',\n", " 57328: 'Home',\n", " 39155: 'Away',\n", " 116216: 'Away',\n", " 61933: 'Away',\n", " 78916: 'Away',\n", " 243505: 'Away',\n", " 233425: 'Away',\n", " 49262: 'Away',\n", " 50175: 'Away',\n", " 111478: 'Away',\n", " 243016: 'Away',\n", " 235382: 'Away',\n", " 232792: 'Away',\n", " 209045: 'Away',\n", " 60307: 'Away',\n", " 433589: 'Away',\n", " 115382: 'Away',\n", " 83299: 'Away',\n", " 215059: 'Away',\n", " 109345: 'Away',\n", " 179268: 'Away'}" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict_home_away_players " ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [], "source": [ "# Map the values to the data (current a hard coded way, will replace with a loop shortly)\n", "dict_home_away_players_cry_bri = {'55037_x': 'Home_8_x',\n", " '50471_x': 'Home_18_x',\n", " '80146_x': 'Home_9_x',\n", " '82403_x': 'Home_11_x',\n", " '108413_x': 'Home_12_x',\n", " '199670_x': 'Home_22_x',\n", " '232787_x': 'Home_23_x',\n", " '174874_x': 'Home_16_x',\n", " '244723_x': 'Home_3_x',\n", " '66975_x': 'Home_4_x',\n", " '55494_x': 'Home_2_x',\n", " '209036_x': 'Home_6_x',\n", " '54861_x': 'Home_20_x',\n", " '86417_x': 'Home_15_x',\n", " '105666_x': 'Home_1_x',\n", " '231747_x': 'Home_14_x',\n", " '40836_x': 'Home_13_x',\n", " '58786_x': 'Home_34_x',\n", " '443661_x': 'Home_17_x',\n", " '57328_x': 'Home_17_x',\n", " \n", " '55037_y': 'Home_8_y',\n", " '50471_y': 'Home_18_y',\n", " '80146_y': 'Home_9_y',\n", " '82403_y': 'Home_11_y',\n", " '108413_y': 'Home_12_y',\n", " '199670_y': 'Home_22_y',\n", " '232787_y': 'Home_23_y',\n", " '174874_y': 'Home_16_y',\n", " '244723_y': 'Home_3_y',\n", " '66975_y': 'Home_4_y',\n", " '55494_y': 'Home_2_y',\n", " '209036_y': 'Home_6_y',\n", " '54861_y': 'Home_20_y',\n", " '86417_y': 'Home_15_y',\n", " '105666_y': 'Home_1_y',\n", " '231747_y': 'Home_14_y',\n", " '40836_y': 'Home_13_y',\n", " '58786_y': 'Home_34_y',\n", " '443661_y': 'Home_17_y',\n", " '57328_y': 'Home_17_y',\n", " \n", " '55037_d': 'Home_8_d',\n", " '50471_d': 'Home_18_d',\n", " '80146_d': 'Home_9_d',\n", " '82403_d': 'Home_11_d',\n", " '108413_d': 'Home_12_d',\n", " '199670_d': 'Home_22_d',\n", " '232787_d': 'Home_23_d',\n", " '174874_d': 'Home_16_d',\n", " '244723_d': 'Home_3_d',\n", " '66975_d': 'Home_4_d',\n", " '55494_d': 'Home_2_d',\n", " '209036_d': 'Home_6_d',\n", " '54861_d': 'Home_20_d',\n", " '86417_d': 'Home_15_d',\n", " '105666_d': 'Home_1_d',\n", " '231747_d': 'Home_14_d',\n", " '40836_d': 'Home_13_d',\n", " '58786_d': 'Home_34_d',\n", " '443661_d': 'Home_17_d',\n", " '57328_d': 'Home_17_d',\n", " \n", " '55037_s': 'Home_8_s',\n", " '50471_s': 'Home_18_s',\n", " '80146_s': 'Home_9_s',\n", " '82403_s': 'Home_11_s',\n", " '108413_s': 'Home_12_s',\n", " '199670_s': 'Home_22_s',\n", " '232787_s': 'Home_23_s',\n", " '174874_s': 'Home_16_s',\n", " '244723_s': 'Home_3_s',\n", " '66975_s': 'Home_4_s',\n", " '55494_s': 'Home_2_s',\n", " '209036_s': 'Home_6_s',\n", " '54861_s': 'Home_20_s',\n", " '86417_s': 'Home_15_s',\n", " '105666_s': 'Home_1_s',\n", " '231747_s': 'Home_14_s',\n", " '40836_s': 'Home_13_s',\n", " '58786_s': 'Home_34_s',\n", " '443661_s': 'Home_17_s',\n", " '57328_s': 'Home_17_s', \n", " \n", " '39155_x': 'Away_14_x',\n", " '116216_x': 'Away_11_x',\n", " '61933_x': 'Away_24_x',\n", " '78916_x': 'Away_33_x',\n", " '243505_x': 'Away_15_x',\n", " '233425_x': 'Away_7_x',\n", " '49262_x': 'Away_23_x',\n", " '50175_x': 'Away_18_x',\n", " '111478_x': 'Away_34_x',\n", " '243016_x': 'Away_10_x',\n", " '235382_x': 'Away_17_x',\n", " '232792_x': 'Away_2_x',\n", " '209045_x': 'Away_30_x',\n", " '60307_x': 'Away_13_x',\n", " '433589_x': 'Away_28_x',\n", " '115382_x': 'Away_9_x',\n", " '83299_x': 'Away_5_x',\n", " '215059_x': 'Away_1_x',\n", " '109345_x': 'Away_20_x',\n", " '179268_x': 'Away_3_x',\n", " \n", " '39155_y': 'Away_14_y',\n", " '116216_y': 'Away_11_y',\n", " '61933_y': 'Away_24_y',\n", " '78916_y': 'Away_33_y',\n", " '243505_y': 'Away_15_y',\n", " '233425_y': 'Away_7_y',\n", " '49262_y': 'Away_23_y',\n", " '50175_y': 'Away_18_y',\n", " '111478_y': 'Away_34_y',\n", " '243016_y': 'Away_10_y',\n", " '235382_y': 'Away_17_y',\n", " '232792_y': 'Away_2_y',\n", " '209045_y': 'Away_30_y',\n", " '60307_y': 'Away_13_y',\n", " '433589_y': 'Away_28_y',\n", " '115382_y': 'Away_9_y',\n", " '83299_y': 'Away_5_y',\n", " '215059_y': 'Away_1_y',\n", " '109345_y': 'Away_20_y',\n", " '179268_y': 'Away_3_y',\n", " \n", " '39155_d': 'Away_14_d',\n", " '116216_d': 'Away_11_d',\n", " '61933_d': 'Away_24_d',\n", " '78916_d': 'Away_33_d',\n", " '243505_d': 'Away_15_d',\n", " '233425_d': 'Away_7_d',\n", " '49262_d': 'Away_23_d',\n", " '50175_d': 'Away_18_d',\n", " '111478_d': 'Away_34_d',\n", " '243016_d': 'Away_10_d',\n", " '235382_d': 'Away_17_d',\n", " '232792_d': 'Away_2_d',\n", " '209045_d': 'Away_30_d',\n", " '60307_d': 'Away_13_d',\n", " '433589_d': 'Away_28_d',\n", " '115382_d': 'Away_9_d',\n", " '83299_d': 'Away_5_d',\n", " '215059_d': 'Away_1_d',\n", " '109345_d': 'Away_20_d',\n", " '179268_d': 'Away_3_d',\n", " \n", " '39155_s': 'Away_14_s',\n", " '116216_s': 'Away_11_s',\n", " '61933_s': 'Away_24_s',\n", " '78916_s': 'Away_33_s',\n", " '243505_s': 'Away_15_s',\n", " '233425_s': 'Away_7_s',\n", " '49262_s': 'Away_23_s',\n", " '50175_s': 'Away_18_s',\n", " '111478_s': 'Away_34_s',\n", " '243016_s': 'Away_10_s',\n", " '235382_s': 'Away_17_s',\n", " '232792_s': 'Away_2_s',\n", " '209045_s': 'Away_30_s',\n", " '60307_s': 'Away_13_s',\n", " '433589_s': 'Away_28_s',\n", " '115382_s': 'Away_9_s',\n", " '83299_s': 'Away_5_s',\n", " '215059_s': 'Away_1_s',\n", " '109345_s': 'Away_20_s',\n", " '179268_s': 'Away_3_s'\n", " }" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [], "source": [ "## Map Qualifier Names to Qualifier IDs\n", "df_tracking_cry_bri = df_tracking_cry_bri.rename(columns=dict_home_away_players_cry_bri)" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Frame', 'Period', 'Time [s]', 'Ball State', 'Ball Owning Team ID',\n", " 'ball_x', 'ball_y', 'Home_18_x', 'Home_18_y', 'Home_18_d',\n", " ...\n", " 'Home_8_d', 'Home_8_s', 'Away_7_x', 'Away_7_y', 'Away_7_d', 'Away_7_s',\n", " 'Home_15_x', 'Home_15_y', 'Home_15_d', 'Home_15_s'],\n", " dtype='object', length=119)" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## Display columns\n", "df_tracking_cry_bri.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.4. Separate Home and Away DataFrames\n", "For compatibility with [Laurie Shaw](https://twitter.com/EightyFivePoint)'s Metrica Sports Tracking data library [`LaurieOnTracking`](https://github.com/Friends-of-Tracking-Data-FoTD/LaurieOnTracking), Home and Away DataFrames are separated. This is done using the custom `create_home_and_away_dfs` that I have written (see the top the top of the notebook)" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [], "source": [ "# Separate Home and Away DataFrames\n", "df_tracking_home_cry_lei, df_tracking_away_cry_lei = create_home_and_away_dfs(df_tracking_cry_lei)\n", "df_tracking_home_cry_bri, df_tracking_away_cry_bri = create_home_and_away_dfs(df_tracking_cry_bri)" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FramePeriodTime [s]Ball StateBall Owning Team IDball_xball_yHome_4_xHome_4_yHome_4_dHome_4_sHome_2_xHome_2_yHome_2_dHome_2_sHome_9_xHome_9_yHome_9_dHome_9_sHome_13_xHome_13_yHome_13_dHome_13_sHome_18_xHome_18_yHome_18_dHome_18_sHome_22_xHome_22_yHome_22_dHome_22_sHome_3_xHome_3_yHome_3_dHome_3_sHome_11_xHome_11_yHome_11_dHome_11_sHome_6_xHome_6_yHome_6_dHome_6_sHome_23_xHome_23_yHome_23_dHome_23_sHome_16_xHome_16_yHome_16_dHome_16_sHome_7_xHome_7_yHome_7_dHome_7_sHome_15_xHome_15_yHome_15_dHome_15_sHome_20_xHome_20_yHome_20_dHome_20_s
0010.00dead310.040.090.60-9.08NaNNaN11.4310.22NaNNaN0.219.47NaNNaN42.10-0.19NaNNaN-0.360.35NaNNaN-0.57-20.55NaNNaN7.63-25.09NaNNaN1.22-30.53NaNNaN14.71-12.51NaNNaN0.512.82NaNNaN19.240.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1110.04alive310.830.090.56-9.07NaNNaN11.4110.22NaNNaN0.229.47NaNNaN42.11-0.19NaNNaN-0.350.35NaNNaN-0.64-20.47NaNNaN7.62-25.09NaNNaN1.24-30.53NaNNaN14.70-12.52NaNNaN0.502.81NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2210.08alive311.340.090.53-9.07NaNNaN11.4110.21NaNNaN0.229.46NaNNaN42.11-0.19NaNNaN-0.340.34NaNNaN-0.71-20.40NaNNaN7.62-25.08NaNNaN1.25-30.53NaNNaN14.70-12.53NaNNaN0.492.80NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3310.12alive312.030.100.50-9.06NaNNaN11.3910.21NaNNaN0.239.45NaNNaN42.11-0.19NaNNaN-0.350.34NaNNaN-0.79-20.31NaNNaN7.60-25.08NaNNaN1.26-30.53NaNNaN14.69-12.54NaNNaN0.472.78NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4410.16alive312.850.110.46-9.06NaNNaN11.4010.19NaNNaN0.259.43NaNNaN42.11-0.19NaNNaN-0.360.33NaNNaN-0.88-20.23NaNNaN7.59-25.07NaNNaN1.27-30.53NaNNaN14.68-12.56NaNNaN0.462.77NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Frame Period Time [s] Ball State Ball Owning Team ID ball_x ball_y \\\n", "0 0 1 0.00 dead 31 0.04 0.09 \n", "1 1 1 0.04 alive 31 0.83 0.09 \n", "2 2 1 0.08 alive 31 1.34 0.09 \n", "3 3 1 0.12 alive 31 2.03 0.10 \n", "4 4 1 0.16 alive 31 2.85 0.11 \n", "\n", " Home_4_x Home_4_y Home_4_d Home_4_s Home_2_x Home_2_y Home_2_d \\\n", "0 0.60 -9.08 NaN NaN 11.43 10.22 NaN \n", "1 0.56 -9.07 NaN NaN 11.41 10.22 NaN \n", "2 0.53 -9.07 NaN NaN 11.41 10.21 NaN \n", "3 0.50 -9.06 NaN NaN 11.39 10.21 NaN \n", "4 0.46 -9.06 NaN NaN 11.40 10.19 NaN \n", "\n", " Home_2_s Home_9_x Home_9_y Home_9_d Home_9_s Home_13_x Home_13_y \\\n", "0 NaN 0.21 9.47 NaN NaN 42.10 -0.19 \n", "1 NaN 0.22 9.47 NaN NaN 42.11 -0.19 \n", "2 NaN 0.22 9.46 NaN NaN 42.11 -0.19 \n", "3 NaN 0.23 9.45 NaN NaN 42.11 -0.19 \n", "4 NaN 0.25 9.43 NaN NaN 42.11 -0.19 \n", "\n", " Home_13_d Home_13_s Home_18_x Home_18_y Home_18_d Home_18_s \\\n", "0 NaN NaN -0.36 0.35 NaN NaN \n", "1 NaN NaN -0.35 0.35 NaN NaN \n", "2 NaN NaN -0.34 0.34 NaN NaN \n", "3 NaN NaN -0.35 0.34 NaN NaN \n", "4 NaN NaN -0.36 0.33 NaN NaN \n", "\n", " Home_22_x Home_22_y Home_22_d Home_22_s Home_3_x Home_3_y Home_3_d \\\n", "0 -0.57 -20.55 NaN NaN 7.63 -25.09 NaN \n", "1 -0.64 -20.47 NaN NaN 7.62 -25.09 NaN \n", "2 -0.71 -20.40 NaN NaN 7.62 -25.08 NaN \n", "3 -0.79 -20.31 NaN NaN 7.60 -25.08 NaN \n", "4 -0.88 -20.23 NaN NaN 7.59 -25.07 NaN \n", "\n", " Home_3_s Home_11_x Home_11_y Home_11_d Home_11_s Home_6_x Home_6_y \\\n", "0 NaN 1.22 -30.53 NaN NaN 14.71 -12.51 \n", "1 NaN 1.24 -30.53 NaN NaN 14.70 -12.52 \n", "2 NaN 1.25 -30.53 NaN NaN 14.70 -12.53 \n", "3 NaN 1.26 -30.53 NaN NaN 14.69 -12.54 \n", "4 NaN 1.27 -30.53 NaN NaN 14.68 -12.56 \n", "\n", " Home_6_d Home_6_s Home_23_x Home_23_y Home_23_d Home_23_s Home_16_x \\\n", "0 NaN NaN 0.51 2.82 NaN NaN 19.24 \n", "1 NaN NaN 0.50 2.81 NaN NaN 19.23 \n", "2 NaN NaN 0.49 2.80 NaN NaN 19.23 \n", "3 NaN NaN 0.47 2.78 NaN NaN 19.23 \n", "4 NaN NaN 0.46 2.77 NaN NaN 19.23 \n", "\n", " Home_16_y Home_16_d Home_16_s Home_7_x Home_7_y Home_7_d Home_7_s \\\n", "0 0.54 NaN NaN NaN NaN NaN NaN \n", "1 0.54 NaN NaN NaN NaN NaN NaN \n", "2 0.54 NaN NaN NaN NaN NaN NaN \n", "3 0.54 NaN NaN NaN NaN NaN NaN \n", "4 0.54 NaN NaN NaN NaN NaN NaN \n", "\n", " Home_15_x Home_15_y Home_15_d Home_15_s Home_20_x Home_20_y \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Home_20_d Home_20_s \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN " ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display Home DataFrame\n", "df_tracking_home_cry_lei.head()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FramePeriodTime [s]Ball StateBall Owning Team IDball_xball_yAway_9_xAway_9_yAway_9_dAway_9_sAway_1_xAway_1_yAway_1_dAway_1_sAway_20_xAway_20_yAway_20_dAway_20_sAway_4_xAway_4_yAway_4_dAway_4_sAway_5_xAway_5_yAway_5_dAway_5_sAway_14_xAway_14_yAway_14_dAway_14_sAway_7_xAway_7_yAway_7_dAway_7_sAway_23_xAway_23_yAway_23_dAway_23_sAway_8_xAway_8_yAway_8_dAway_8_sAway_37_xAway_37_yAway_37_dAway_37_sAway_27_xAway_27_yAway_27_dAway_27_sAway_42_xAway_42_yAway_42_dAway_42_sAway_10_xAway_10_yAway_10_dAway_10_sAway_11_xAway_11_yAway_11_dAway_11_s
0010.00dead310.040.09-0.939.31NaNNaN-50.430.12NaNNaN-10.17-19.71NaNNaN-16.67-16.05NaNNaN-13.949.96NaNNaN0.49-10.92NaNNaN-3.1810.89NaNNaN-15.10-0.99NaNNaN-8.980.43NaNNaN-0.99-20.88NaNNaN-14.75-27.43NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1110.04alive310.830.09-0.899.25NaNNaN-50.420.12NaNNaN-10.13-19.70NaNNaN-16.68-16.06NaNNaN-13.949.96NaNNaN0.59-10.86NaNNaN-3.1910.91NaNNaN-15.13-0.99NaNNaN-8.950.44NaNNaN-0.99-20.83NaNNaN-14.75-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2210.08alive311.340.09-0.849.19NaNNaN-50.430.13NaNNaN-10.09-19.69NaNNaN-16.69-16.07NaNNaN-13.939.99NaNNaN0.70-10.80NaNNaN-3.2010.94NaNNaN-15.16-0.99NaNNaN-8.920.44NaNNaN-1.00-20.78NaNNaN-14.76-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
3310.12alive312.030.10-0.779.12NaNNaN-50.420.13NaNNaN-10.05-19.67NaNNaN-16.69-16.09NaNNaN-13.9210.02NaNNaN0.80-10.75NaNNaN-3.2210.96NaNNaN-15.16-1.00NaNNaN-8.880.44NaNNaN-1.02-20.73NaNNaN-14.76-27.41NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
4410.16alive312.850.11-0.709.04NaNNaN-50.420.13NaNNaN-10.02-19.65NaNNaN-16.70-16.09NaNNaN-13.9310.04NaNNaN0.91-10.69NaNNaN-3.2211.00NaNNaN-15.20-1.01NaNNaN-8.910.45NaNNaN-1.04-20.69NaNNaN-14.78-27.40NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Frame Period Time [s] Ball State Ball Owning Team ID ball_x ball_y \\\n", "0 0 1 0.00 dead 31 0.04 0.09 \n", "1 1 1 0.04 alive 31 0.83 0.09 \n", "2 2 1 0.08 alive 31 1.34 0.09 \n", "3 3 1 0.12 alive 31 2.03 0.10 \n", "4 4 1 0.16 alive 31 2.85 0.11 \n", "\n", " Away_9_x Away_9_y Away_9_d Away_9_s Away_1_x Away_1_y Away_1_d \\\n", "0 -0.93 9.31 NaN NaN -50.43 0.12 NaN \n", "1 -0.89 9.25 NaN NaN -50.42 0.12 NaN \n", "2 -0.84 9.19 NaN NaN -50.43 0.13 NaN \n", "3 -0.77 9.12 NaN NaN -50.42 0.13 NaN \n", "4 -0.70 9.04 NaN NaN -50.42 0.13 NaN \n", "\n", " Away_1_s Away_20_x Away_20_y Away_20_d Away_20_s Away_4_x Away_4_y \\\n", "0 NaN -10.17 -19.71 NaN NaN -16.67 -16.05 \n", "1 NaN -10.13 -19.70 NaN NaN -16.68 -16.06 \n", "2 NaN -10.09 -19.69 NaN NaN -16.69 -16.07 \n", "3 NaN -10.05 -19.67 NaN NaN -16.69 -16.09 \n", "4 NaN -10.02 -19.65 NaN NaN -16.70 -16.09 \n", "\n", " Away_4_d Away_4_s Away_5_x Away_5_y Away_5_d Away_5_s Away_14_x \\\n", "0 NaN NaN -13.94 9.96 NaN NaN 0.49 \n", "1 NaN NaN -13.94 9.96 NaN NaN 0.59 \n", "2 NaN NaN -13.93 9.99 NaN NaN 0.70 \n", "3 NaN NaN -13.92 10.02 NaN NaN 0.80 \n", "4 NaN NaN -13.93 10.04 NaN NaN 0.91 \n", "\n", " Away_14_y Away_14_d Away_14_s Away_7_x Away_7_y Away_7_d Away_7_s \\\n", "0 -10.92 NaN NaN -3.18 10.89 NaN NaN \n", "1 -10.86 NaN NaN -3.19 10.91 NaN NaN \n", "2 -10.80 NaN NaN -3.20 10.94 NaN NaN \n", "3 -10.75 NaN NaN -3.22 10.96 NaN NaN \n", "4 -10.69 NaN NaN -3.22 11.00 NaN NaN \n", "\n", " Away_23_x Away_23_y Away_23_d Away_23_s Away_8_x Away_8_y Away_8_d \\\n", "0 -15.10 -0.99 NaN NaN -8.98 0.43 NaN \n", "1 -15.13 -0.99 NaN NaN -8.95 0.44 NaN \n", "2 -15.16 -0.99 NaN NaN -8.92 0.44 NaN \n", "3 -15.16 -1.00 NaN NaN -8.88 0.44 NaN \n", "4 -15.20 -1.01 NaN NaN -8.91 0.45 NaN \n", "\n", " Away_8_s Away_37_x Away_37_y Away_37_d Away_37_s Away_27_x Away_27_y \\\n", "0 NaN -0.99 -20.88 NaN NaN -14.75 -27.43 \n", "1 NaN -0.99 -20.83 NaN NaN -14.75 -27.42 \n", "2 NaN -1.00 -20.78 NaN NaN -14.76 -27.42 \n", "3 NaN -1.02 -20.73 NaN NaN -14.76 -27.41 \n", "4 NaN -1.04 -20.69 NaN NaN -14.78 -27.40 \n", "\n", " Away_27_d Away_27_s Away_42_x Away_42_y Away_42_d Away_42_s \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Away_10_x Away_10_y Away_10_d Away_10_s Away_11_x Away_11_y \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Away_11_d Away_11_s \n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN " ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display Away DataFrame\n", "df_tracking_away_cry_lei.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.5. Calculate Player Velocities\n", "Determine the velocity of each player at a given timestep using the `calc_player_velocities` function from the `mvel` library." ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [], "source": [ "# Calculate player velocities\n", "\n", "## 03/10/2021: Crystal Palace (2) vs. (2) Leicester City (g2210334)\n", "\n", "### Home\n", "df_tracking_home_cry_lei = svel.calc_player_velocities(df_tracking_home_cry_lei,\n", " smoothing=True,\n", " filter_='moving_average',\n", " maxspeed=12\n", " ) # filter_='Savitzky-Golay'\n", "\n", "### Away\n", "df_tracking_away_cry_lei = svel.calc_player_velocities(df_tracking_away_cry_lei,\n", " smoothing=True,\n", " filter_='moving_average',\n", " maxspeed=12\n", " )\n", "\n", "## 27/09/2021: Crystal Palace (1) vs. (1) Brighton & Hove Albion (g2210324)\n", "\n", "### Home\n", "df_tracking_home_cry_bri = svel.calc_player_velocities(df_tracking_home_cry_bri,\n", " smoothing=True,\n", " filter_='moving_average',\n", " maxspeed=12\n", " ) # filter_='Savitzky-Golay'\n", "\n", "### Away\n", "df_tracking_away_cry_bri = svel.calc_player_velocities(df_tracking_away_cry_bri,\n", " smoothing=True,\n", " filter_='moving_average',\n", " maxspeed=12\n", " )" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FramePeriodTime [s]Ball StateBall Owning Team IDball_xball_yHome_4_xHome_4_yHome_4_dHome_4_sHome_2_xHome_2_yHome_2_dHome_2_sHome_9_xHome_9_yHome_9_dHome_9_sHome_13_xHome_13_yHome_13_dHome_13_sHome_18_xHome_18_yHome_18_dHome_18_sHome_22_xHome_22_yHome_22_dHome_22_sHome_3_xHome_3_yHome_3_dHome_3_sHome_11_xHome_11_yHome_11_dHome_11_sHome_6_xHome_6_yHome_6_dHome_6_sHome_23_xHome_23_yHome_23_dHome_23_sHome_16_xHome_16_yHome_16_dHome_16_sHome_7_xHome_7_yHome_7_dHome_7_sHome_15_xHome_15_yHome_15_dHome_15_sHome_20_xHome_20_yHome_20_dHome_20_sHome_4_vxHome_4_vyHome_4_speedHome_2_vxHome_2_vyHome_2_speedHome_9_vxHome_9_vyHome_9_speedHome_13_vxHome_13_vyHome_13_speedHome_18_vxHome_18_vyHome_18_speedHome_22_vxHome_22_vyHome_22_speedHome_3_vxHome_3_vyHome_3_speedHome_11_vxHome_11_vyHome_11_speedHome_6_vxHome_6_vyHome_6_speedHome_23_vxHome_23_vyHome_23_speedHome_16_vxHome_16_vyHome_16_speedHome_7_vxHome_7_vyHome_7_speedHome_15_vxHome_15_vyHome_15_speedHome_20_vxHome_20_vyHome_20_speed
0010.00dead310.040.090.60-9.08NaNNaN11.4310.22NaNNaN0.219.47NaNNaN42.10-0.19NaNNaN-0.360.35NaNNaN-0.57-20.55NaNNaN7.63-25.09NaNNaN1.22-30.53NaNNaN14.71-12.51NaNNaN0.512.82NaNNaN19.240.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1110.04alive310.830.090.56-9.07NaNNaN11.4110.22NaNNaN0.229.47NaNNaN42.11-0.19NaNNaN-0.350.35NaNNaN-0.64-20.47NaNNaN7.62-25.09NaNNaN1.24-30.53NaNNaN14.70-12.52NaNNaN0.502.81NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN-1.000.251.030776-0.500.000.5000000.250.000.2500000.250.00.250.250.000.250000-1.752.002.657536-0.250.000.2500000.500.00.50-0.25-0.250.353553-0.25-0.250.353553-0.250.00.25NaNNaNNaNNaNNaNNaNNaNNaNNaN
2210.08alive311.340.090.53-9.07NaNNaN11.4110.21NaNNaN0.229.46NaNNaN42.11-0.19NaNNaN-0.340.34NaNNaN-0.71-20.40NaNNaN7.62-25.08NaNNaN1.25-30.53NaNNaN14.70-12.53NaNNaN0.492.80NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN-0.750.000.7500000.00-0.250.2500000.00-0.250.2500000.000.00.000.25-0.250.353553-1.751.752.4748740.000.250.2500000.250.00.250.00-0.250.250000-0.25-0.250.3535530.000.00.00NaNNaNNaNNaNNaNNaNNaNNaNNaN
3310.12alive312.030.100.50-9.06NaNNaN11.3910.21NaNNaN0.239.45NaNNaN42.11-0.19NaNNaN-0.350.34NaNNaN-0.79-20.31NaNNaN7.60-25.08NaNNaN1.26-30.53NaNNaN14.69-12.54NaNNaN0.472.78NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN-0.750.250.790569-0.500.000.5000000.25-0.250.3535530.000.00.00-0.250.000.250000-2.002.253.010399-0.500.000.5000000.250.00.25-0.25-0.250.353553-0.50-0.500.7071070.000.00.00NaNNaNNaNNaNNaNNaNNaNNaNNaN
4410.16alive312.850.110.46-9.06NaNNaN11.4010.19NaNNaN0.259.43NaNNaN42.11-0.19NaNNaN-0.360.33NaNNaN-0.88-20.23NaNNaN7.59-25.07NaNNaN1.27-30.53NaNNaN14.68-12.56NaNNaN0.462.77NaNNaN19.230.54NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN-1.000.001.0000000.25-0.500.5590170.50-0.500.7071070.000.00.00-0.25-0.250.353553-2.252.003.010399-0.250.250.3535530.250.00.25-0.25-0.500.559017-0.25-0.250.3535530.000.00.00NaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Frame Period Time [s] Ball State Ball Owning Team ID ball_x ball_y \\\n", "0 0 1 0.00 dead 31 0.04 0.09 \n", "1 1 1 0.04 alive 31 0.83 0.09 \n", "2 2 1 0.08 alive 31 1.34 0.09 \n", "3 3 1 0.12 alive 31 2.03 0.10 \n", "4 4 1 0.16 alive 31 2.85 0.11 \n", "\n", " Home_4_x Home_4_y Home_4_d Home_4_s Home_2_x Home_2_y Home_2_d \\\n", "0 0.60 -9.08 NaN NaN 11.43 10.22 NaN \n", "1 0.56 -9.07 NaN NaN 11.41 10.22 NaN \n", "2 0.53 -9.07 NaN NaN 11.41 10.21 NaN \n", "3 0.50 -9.06 NaN NaN 11.39 10.21 NaN \n", "4 0.46 -9.06 NaN NaN 11.40 10.19 NaN \n", "\n", " Home_2_s Home_9_x Home_9_y Home_9_d Home_9_s Home_13_x Home_13_y \\\n", "0 NaN 0.21 9.47 NaN NaN 42.10 -0.19 \n", "1 NaN 0.22 9.47 NaN NaN 42.11 -0.19 \n", "2 NaN 0.22 9.46 NaN NaN 42.11 -0.19 \n", "3 NaN 0.23 9.45 NaN NaN 42.11 -0.19 \n", "4 NaN 0.25 9.43 NaN NaN 42.11 -0.19 \n", "\n", " Home_13_d Home_13_s Home_18_x Home_18_y Home_18_d Home_18_s \\\n", "0 NaN NaN -0.36 0.35 NaN NaN \n", "1 NaN NaN -0.35 0.35 NaN NaN \n", "2 NaN NaN -0.34 0.34 NaN NaN \n", "3 NaN NaN -0.35 0.34 NaN NaN \n", "4 NaN NaN -0.36 0.33 NaN NaN \n", "\n", " Home_22_x Home_22_y Home_22_d Home_22_s Home_3_x Home_3_y Home_3_d \\\n", "0 -0.57 -20.55 NaN NaN 7.63 -25.09 NaN \n", "1 -0.64 -20.47 NaN NaN 7.62 -25.09 NaN \n", "2 -0.71 -20.40 NaN NaN 7.62 -25.08 NaN \n", "3 -0.79 -20.31 NaN NaN 7.60 -25.08 NaN \n", "4 -0.88 -20.23 NaN NaN 7.59 -25.07 NaN \n", "\n", " Home_3_s Home_11_x Home_11_y Home_11_d Home_11_s Home_6_x Home_6_y \\\n", "0 NaN 1.22 -30.53 NaN NaN 14.71 -12.51 \n", "1 NaN 1.24 -30.53 NaN NaN 14.70 -12.52 \n", "2 NaN 1.25 -30.53 NaN NaN 14.70 -12.53 \n", "3 NaN 1.26 -30.53 NaN NaN 14.69 -12.54 \n", "4 NaN 1.27 -30.53 NaN NaN 14.68 -12.56 \n", "\n", " Home_6_d Home_6_s Home_23_x Home_23_y Home_23_d Home_23_s Home_16_x \\\n", "0 NaN NaN 0.51 2.82 NaN NaN 19.24 \n", "1 NaN NaN 0.50 2.81 NaN NaN 19.23 \n", "2 NaN NaN 0.49 2.80 NaN NaN 19.23 \n", "3 NaN NaN 0.47 2.78 NaN NaN 19.23 \n", "4 NaN NaN 0.46 2.77 NaN NaN 19.23 \n", "\n", " Home_16_y Home_16_d Home_16_s Home_7_x Home_7_y Home_7_d Home_7_s \\\n", "0 0.54 NaN NaN NaN NaN NaN NaN \n", "1 0.54 NaN NaN NaN NaN NaN NaN \n", "2 0.54 NaN NaN NaN NaN NaN NaN \n", "3 0.54 NaN NaN NaN NaN NaN NaN \n", "4 0.54 NaN NaN NaN NaN NaN NaN \n", "\n", " Home_15_x Home_15_y Home_15_d Home_15_s Home_20_x Home_20_y \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Home_20_d Home_20_s Home_4_vx Home_4_vy Home_4_speed Home_2_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN -1.00 0.25 1.030776 -0.50 \n", "2 NaN NaN -0.75 0.00 0.750000 0.00 \n", "3 NaN NaN -0.75 0.25 0.790569 -0.50 \n", "4 NaN NaN -1.00 0.00 1.000000 0.25 \n", "\n", " Home_2_vy Home_2_speed Home_9_vx Home_9_vy Home_9_speed Home_13_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 0.00 0.500000 0.25 0.00 0.250000 0.25 \n", "2 -0.25 0.250000 0.00 -0.25 0.250000 0.00 \n", "3 0.00 0.500000 0.25 -0.25 0.353553 0.00 \n", "4 -0.50 0.559017 0.50 -0.50 0.707107 0.00 \n", "\n", " Home_13_vy Home_13_speed Home_18_vx Home_18_vy Home_18_speed \\\n", "0 NaN NaN NaN NaN NaN \n", "1 0.0 0.25 0.25 0.00 0.250000 \n", "2 0.0 0.00 0.25 -0.25 0.353553 \n", "3 0.0 0.00 -0.25 0.00 0.250000 \n", "4 0.0 0.00 -0.25 -0.25 0.353553 \n", "\n", " Home_22_vx Home_22_vy Home_22_speed Home_3_vx Home_3_vy Home_3_speed \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 -1.75 2.00 2.657536 -0.25 0.00 0.250000 \n", "2 -1.75 1.75 2.474874 0.00 0.25 0.250000 \n", "3 -2.00 2.25 3.010399 -0.50 0.00 0.500000 \n", "4 -2.25 2.00 3.010399 -0.25 0.25 0.353553 \n", "\n", " Home_11_vx Home_11_vy Home_11_speed Home_6_vx Home_6_vy Home_6_speed \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 0.50 0.0 0.50 -0.25 -0.25 0.353553 \n", "2 0.25 0.0 0.25 0.00 -0.25 0.250000 \n", "3 0.25 0.0 0.25 -0.25 -0.25 0.353553 \n", "4 0.25 0.0 0.25 -0.25 -0.50 0.559017 \n", "\n", " Home_23_vx Home_23_vy Home_23_speed Home_16_vx Home_16_vy \\\n", "0 NaN NaN NaN NaN NaN \n", "1 -0.25 -0.25 0.353553 -0.25 0.0 \n", "2 -0.25 -0.25 0.353553 0.00 0.0 \n", "3 -0.50 -0.50 0.707107 0.00 0.0 \n", "4 -0.25 -0.25 0.353553 0.00 0.0 \n", "\n", " Home_16_speed Home_7_vx Home_7_vy Home_7_speed Home_15_vx Home_15_vy \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 0.25 NaN NaN NaN NaN NaN \n", "2 0.00 NaN NaN NaN NaN NaN \n", "3 0.00 NaN NaN NaN NaN NaN \n", "4 0.00 NaN NaN NaN NaN NaN \n", "\n", " Home_15_speed Home_20_vx Home_20_vy Home_20_speed \n", "0 NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN " ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display Home DataFrame\n", "df_tracking_home_cry_lei.head()" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FramePeriodTime [s]Ball StateBall Owning Team IDball_xball_yAway_9_xAway_9_yAway_9_dAway_9_sAway_1_xAway_1_yAway_1_dAway_1_sAway_20_xAway_20_yAway_20_dAway_20_sAway_4_xAway_4_yAway_4_dAway_4_sAway_5_xAway_5_yAway_5_dAway_5_sAway_14_xAway_14_yAway_14_dAway_14_sAway_7_xAway_7_yAway_7_dAway_7_sAway_23_xAway_23_yAway_23_dAway_23_sAway_8_xAway_8_yAway_8_dAway_8_sAway_37_xAway_37_yAway_37_dAway_37_sAway_27_xAway_27_yAway_27_dAway_27_sAway_42_xAway_42_yAway_42_dAway_42_sAway_10_xAway_10_yAway_10_dAway_10_sAway_11_xAway_11_yAway_11_dAway_11_sAway_9_vxAway_9_vyAway_9_speedAway_1_vxAway_1_vyAway_1_speedAway_20_vxAway_20_vyAway_20_speedAway_4_vxAway_4_vyAway_4_speedAway_5_vxAway_5_vyAway_5_speedAway_14_vxAway_14_vyAway_14_speedAway_7_vxAway_7_vyAway_7_speedAway_23_vxAway_23_vyAway_23_speedAway_8_vxAway_8_vyAway_8_speedAway_37_vxAway_37_vyAway_37_speedAway_27_vxAway_27_vyAway_27_speedAway_42_vxAway_42_vyAway_42_speedAway_10_vxAway_10_vyAway_10_speedAway_11_vxAway_11_vyAway_11_speed
0010.00dead310.040.09-0.939.31NaNNaN-50.430.12NaNNaN-10.17-19.71NaNNaN-16.67-16.05NaNNaN-13.949.96NaNNaN0.49-10.92NaNNaN-3.1810.89NaNNaN-15.10-0.99NaNNaN-8.980.43NaNNaN-0.99-20.88NaNNaN-14.75-27.43NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
1110.04alive310.830.09-0.899.25NaNNaN-50.420.12NaNNaN-10.13-19.70NaNNaN-16.68-16.06NaNNaN-13.949.96NaNNaN0.59-10.86NaNNaN-3.1910.91NaNNaN-15.13-0.99NaNNaN-8.950.44NaNNaN-0.99-20.83NaNNaN-14.75-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN1.00-1.501.8027760.250.000.2500001.000.251.030776-0.25-0.250.3535530.000.000.0000002.501.502.915476-0.250.500.559017-0.750.000.7500000.750.250.7905690.001.251.2500000.000.250.250000NaNNaNNaNNaNNaNNaNNaNNaNNaN
2210.08alive311.340.09-0.849.19NaNNaN-50.430.13NaNNaN-10.09-19.69NaNNaN-16.69-16.07NaNNaN-13.939.99NaNNaN0.70-10.80NaNNaN-3.2010.94NaNNaN-15.16-0.99NaNNaN-8.920.44NaNNaN-1.00-20.78NaNNaN-14.76-27.42NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN1.25-1.501.952562-0.250.250.3535531.000.251.030776-0.25-0.250.3535530.250.750.7905692.751.503.132491-0.250.750.790569-0.750.000.7500000.750.000.750000-0.251.251.274755-0.250.000.250000NaNNaNNaNNaNNaNNaNNaNNaNNaN
3310.12alive312.030.10-0.779.12NaNNaN-50.420.13NaNNaN-10.05-19.67NaNNaN-16.69-16.09NaNNaN-13.9210.02NaNNaN0.80-10.75NaNNaN-3.2210.96NaNNaN-15.16-1.00NaNNaN-8.880.44NaNNaN-1.02-20.73NaNNaN-14.76-27.41NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN1.75-1.752.4748740.250.000.2500001.000.501.1180340.00-0.500.5000000.250.750.7905692.501.252.795085-0.500.500.7071070.00-0.250.2500001.000.001.000000-0.501.251.3462910.000.250.250000NaNNaNNaNNaNNaNNaNNaNNaNNaN
4410.16alive312.850.11-0.709.04NaNNaN-50.420.13NaNNaN-10.02-19.65NaNNaN-16.70-16.09NaNNaN-13.9310.04NaNNaN0.91-10.69NaNNaN-3.2211.00NaNNaN-15.20-1.01NaNNaN-8.910.45NaNNaN-1.04-20.69NaNNaN-14.78-27.40NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN1.75-2.002.6575360.000.000.0000000.750.500.901388-0.250.000.250000-0.250.500.5590172.751.503.1324910.001.001.000000-1.00-0.251.030776-0.750.250.790569-0.501.001.118034-0.500.250.559017NaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " Frame Period Time [s] Ball State Ball Owning Team ID ball_x ball_y \\\n", "0 0 1 0.00 dead 31 0.04 0.09 \n", "1 1 1 0.04 alive 31 0.83 0.09 \n", "2 2 1 0.08 alive 31 1.34 0.09 \n", "3 3 1 0.12 alive 31 2.03 0.10 \n", "4 4 1 0.16 alive 31 2.85 0.11 \n", "\n", " Away_9_x Away_9_y Away_9_d Away_9_s Away_1_x Away_1_y Away_1_d \\\n", "0 -0.93 9.31 NaN NaN -50.43 0.12 NaN \n", "1 -0.89 9.25 NaN NaN -50.42 0.12 NaN \n", "2 -0.84 9.19 NaN NaN -50.43 0.13 NaN \n", "3 -0.77 9.12 NaN NaN -50.42 0.13 NaN \n", "4 -0.70 9.04 NaN NaN -50.42 0.13 NaN \n", "\n", " Away_1_s Away_20_x Away_20_y Away_20_d Away_20_s Away_4_x Away_4_y \\\n", "0 NaN -10.17 -19.71 NaN NaN -16.67 -16.05 \n", "1 NaN -10.13 -19.70 NaN NaN -16.68 -16.06 \n", "2 NaN -10.09 -19.69 NaN NaN -16.69 -16.07 \n", "3 NaN -10.05 -19.67 NaN NaN -16.69 -16.09 \n", "4 NaN -10.02 -19.65 NaN NaN -16.70 -16.09 \n", "\n", " Away_4_d Away_4_s Away_5_x Away_5_y Away_5_d Away_5_s Away_14_x \\\n", "0 NaN NaN -13.94 9.96 NaN NaN 0.49 \n", "1 NaN NaN -13.94 9.96 NaN NaN 0.59 \n", "2 NaN NaN -13.93 9.99 NaN NaN 0.70 \n", "3 NaN NaN -13.92 10.02 NaN NaN 0.80 \n", "4 NaN NaN -13.93 10.04 NaN NaN 0.91 \n", "\n", " Away_14_y Away_14_d Away_14_s Away_7_x Away_7_y Away_7_d Away_7_s \\\n", "0 -10.92 NaN NaN -3.18 10.89 NaN NaN \n", "1 -10.86 NaN NaN -3.19 10.91 NaN NaN \n", "2 -10.80 NaN NaN -3.20 10.94 NaN NaN \n", "3 -10.75 NaN NaN -3.22 10.96 NaN NaN \n", "4 -10.69 NaN NaN -3.22 11.00 NaN NaN \n", "\n", " Away_23_x Away_23_y Away_23_d Away_23_s Away_8_x Away_8_y Away_8_d \\\n", "0 -15.10 -0.99 NaN NaN -8.98 0.43 NaN \n", "1 -15.13 -0.99 NaN NaN -8.95 0.44 NaN \n", "2 -15.16 -0.99 NaN NaN -8.92 0.44 NaN \n", "3 -15.16 -1.00 NaN NaN -8.88 0.44 NaN \n", "4 -15.20 -1.01 NaN NaN -8.91 0.45 NaN \n", "\n", " Away_8_s Away_37_x Away_37_y Away_37_d Away_37_s Away_27_x Away_27_y \\\n", "0 NaN -0.99 -20.88 NaN NaN -14.75 -27.43 \n", "1 NaN -0.99 -20.83 NaN NaN -14.75 -27.42 \n", "2 NaN -1.00 -20.78 NaN NaN -14.76 -27.42 \n", "3 NaN -1.02 -20.73 NaN NaN -14.76 -27.41 \n", "4 NaN -1.04 -20.69 NaN NaN -14.78 -27.40 \n", "\n", " Away_27_d Away_27_s Away_42_x Away_42_y Away_42_d Away_42_s \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Away_10_x Away_10_y Away_10_d Away_10_s Away_11_x Away_11_y \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN \n", "\n", " Away_11_d Away_11_s Away_9_vx Away_9_vy Away_9_speed Away_1_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN 1.00 -1.50 1.802776 0.25 \n", "2 NaN NaN 1.25 -1.50 1.952562 -0.25 \n", "3 NaN NaN 1.75 -1.75 2.474874 0.25 \n", "4 NaN NaN 1.75 -2.00 2.657536 0.00 \n", "\n", " Away_1_vy Away_1_speed Away_20_vx Away_20_vy Away_20_speed Away_4_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 0.00 0.250000 1.00 0.25 1.030776 -0.25 \n", "2 0.25 0.353553 1.00 0.25 1.030776 -0.25 \n", "3 0.00 0.250000 1.00 0.50 1.118034 0.00 \n", "4 0.00 0.000000 0.75 0.50 0.901388 -0.25 \n", "\n", " Away_4_vy Away_4_speed Away_5_vx Away_5_vy Away_5_speed Away_14_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 -0.25 0.353553 0.00 0.00 0.000000 2.50 \n", "2 -0.25 0.353553 0.25 0.75 0.790569 2.75 \n", "3 -0.50 0.500000 0.25 0.75 0.790569 2.50 \n", "4 0.00 0.250000 -0.25 0.50 0.559017 2.75 \n", "\n", " Away_14_vy Away_14_speed Away_7_vx Away_7_vy Away_7_speed Away_23_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 1.50 2.915476 -0.25 0.50 0.559017 -0.75 \n", "2 1.50 3.132491 -0.25 0.75 0.790569 -0.75 \n", "3 1.25 2.795085 -0.50 0.50 0.707107 0.00 \n", "4 1.50 3.132491 0.00 1.00 1.000000 -1.00 \n", "\n", " Away_23_vy Away_23_speed Away_8_vx Away_8_vy Away_8_speed Away_37_vx \\\n", "0 NaN NaN NaN NaN NaN NaN \n", "1 0.00 0.750000 0.75 0.25 0.790569 0.00 \n", "2 0.00 0.750000 0.75 0.00 0.750000 -0.25 \n", "3 -0.25 0.250000 1.00 0.00 1.000000 -0.50 \n", "4 -0.25 1.030776 -0.75 0.25 0.790569 -0.50 \n", "\n", " Away_37_vy Away_37_speed Away_27_vx Away_27_vy Away_27_speed \\\n", "0 NaN NaN NaN NaN NaN \n", "1 1.25 1.250000 0.00 0.25 0.250000 \n", "2 1.25 1.274755 -0.25 0.00 0.250000 \n", "3 1.25 1.346291 0.00 0.25 0.250000 \n", "4 1.00 1.118034 -0.50 0.25 0.559017 \n", "\n", " Away_42_vx Away_42_vy Away_42_speed Away_10_vx Away_10_vy \\\n", "0 NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN \n", "\n", " Away_10_speed Away_11_vx Away_11_vy Away_11_speed \n", "0 NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN " ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Display Away DataFrame\n", "df_tracking_away_cry_lei.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Exploring the `df_tracking_home` and `df_tracking_away` DataFrames, we can see the additional columns for velocity have been added to the DataFrame. These columns are of the following, but for all the players:\n", "* `Away_101668_vx`\n", "* `Away_101668_vy`\n", "* `Away_101668_speed` i.e. total speed\n", "\n", "These new metrics are all measured in meters per second." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "### 4.6. Reverse direction of players\n", "Reverse direction of a player so that home team is alway attacking right->left i.e. no switch at half time" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [], "source": [ "# Reverse direction of a player so that home team is alway attacking right->left i.e. no switch at half time\n", "df_tracking_home_cry_lei, df_tracking_away_cry_lei = to_single_playing_direction(df_tracking_home_cry_lei, df_tracking_away_cry_lei)\n", "df_tracking_home_cry_bri, df_tracking_away_cry_bri = to_single_playing_direction(df_tracking_home_cry_bri, df_tracking_away_cry_bri)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 5. Export Final DataFrames" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [], "source": [ "# Export DataFrame\n", "\n", "## 03/10/2021: Crystal Palace (2) vs. (2) Leicester City (g2210334)\n", "df_tracking_home_cry_lei.to_csv(os.path.join(data_dir_second_spectrum, 'engineered', 'data', 'g2210334_SecondSpectrum_Trackingdata_Home.csv'), index=None, header=True)\n", "df_tracking_away_cry_lei.to_csv(os.path.join(data_dir_second_spectrum, 'engineered', 'data', 'g2210334_SecondSpectrum_Trackingdata_Away.csv'), index=None, header=True)\n", "\n", "## 27/09/2021: Crystal Palace (1) vs. (1) Brighton & Hove Albion (g2210324)\n", "df_tracking_home_cry_bri.to_csv(os.path.join(data_dir_second_spectrum, 'engineered', 'data', 'g2210324_SecondSpectrum_Trackingdata_Home.csv'), index=None, header=True)\n", "df_tracking_away_cry_bri.to_csv(os.path.join(data_dir_second_spectrum, 'engineered', 'data', 'g2210324_SecondSpectrum_Trackingdata_Away.csv'), index=None, header=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 6. Summary\n", "This notebook parses and engineers [Second Spectrum](https://www.secondspectrum.com/index.html) Tracking data using [pandas](http://pandas.pydata.org/), [`Kloppy`](https://kloppy.pysport.org/), and a custom library of function, based on [Laurie Shaw](https://twitter.com/EightyFivePoint)'s Metrica Sports Tracking data library [`LaurieOnTracking`](https://github.com/Friends-of-Tracking-Data-FoTD/LaurieOnTracking), that has been modified to be compatible with [Second Spectrum](https://www.secondspectrum.com/index.html) Tracking data, which is a different format." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 7. Next Steps\n", "The next stage is to visualise and analyse the tracking data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "\n", "\n", "## 8. References\n", "* [Second Spectrum](https://www.secondspectrum.com/index.html) data\n", "* [`Kloppy`](https://kloppy.pysport.org/)\n", "* BBC Sports pages for the two Premier League matches featuring Crystal Palace:\n", " + [27/09/2021: Crystal Palace (1) vs. (1) Brighton & Hove Albion](https://www.bbc.co.uk/sport/football/58620544) (g2210324)\n", " + [03/10/2021: Crystal Palace (2) vs. (2) Leicester City](https://www.bbc.co.uk/sport/football/58667896) (g2210324)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "***Visit my website [eddwebster.com](https://www.eddwebster.com) or my [GitHub Repository](https://github.com/eddwebster) for more projects. If you'd like to get in contact, my Twitter handle is [@eddwebster](http://www.twitter.com/eddwebster) and my email is: edd.j.webster@gmail.com.***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Back to the top](#top)" ] } ], "metadata": { "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.7.6" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "oldHeight": 642, "position": { "height": "40px", "left": "1118px", "right": "20px", "top": "-7px", "width": "489px" }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "varInspector_section_display": "none", "window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }