{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"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",
"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 # version 1.0.3\n",
"import os # used to read the csv filenames\n",
"import re\n",
"import random\n",
"from io import BytesIO\n",
"from pathlib import Path\n",
"\n",
"# Reading directories\n",
"import glob\n",
"import os\n",
"\n",
"# Working with JSON\n",
"import json\n",
"from pandas.io.json import json_normalize\n",
"from ast import literal_eval\n",
"\n",
"# Data Visualisation\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"plt.style.use('seaborn-whitegrid')\n",
"import missingno as msno # visually display missing data\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('Setup Complete')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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_fbref = os.path.join(base_dir, 'data', 'fbref')\n",
"data_dir_tm = os.path.join(base_dir, 'data', 'tm')\n",
"data_dir_wyscout = os.path.join(base_dir, 'data', 'wyscout')\n",
"img_dir = os.path.join(base_dir, 'img')\n",
"fig_dir = os.path.join(base_dir, 'img', 'fig')\n",
"video_dir = os.path.join(base_dir, 'video')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['../../data/wyscout/engineered/combined/wyscout_events_big5_1718.csv', '../../data/wyscout/engineered/combined/wyscout_aggregated_team_big5_1718.csv', '../../data/wyscout/engineered/combined/wyscout_aggregated_fixtures_big5_1718.csv']\n"
]
}
],
"source": [
"# Show files in directory\n",
"print(glob.glob(data_dir_wyscout + '/engineered/combined/*.csv'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"df_wyscout = pd.read_csv(data_dir_wyscout + '/engineered/combined/wyscout_events_big5_1718.csv')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"pd.set_option('display.max_columns', None)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" eventId | \n",
" subEventName | \n",
" tags | \n",
" playerId | \n",
" positions | \n",
" matchId | \n",
" eventName | \n",
" teamId | \n",
" matchPeriod | \n",
" eventSec | \n",
" subEventId | \n",
" id | \n",
" status | \n",
" roundId | \n",
" gameweek | \n",
" seasonId | \n",
" dateutc | \n",
" winner | \n",
" venue | \n",
" wyId_x | \n",
" label | \n",
" date | \n",
" referees | \n",
" duration | \n",
" competitionId | \n",
" league_name | \n",
" wyId_y | \n",
" country | \n",
" weight | \n",
" firstName | \n",
" middleName | \n",
" lastName | \n",
" birthDate | \n",
" height | \n",
" wyId_x.1 | \n",
" foot | \n",
" shortName | \n",
" passportArea.name | \n",
" role.name | \n",
" birthArea.name | \n",
" fullName | \n",
" teamName | \n",
" wyId_y.1 | \n",
" fixture | \n",
" score_home_away | \n",
" team_home | \n",
" team_away | \n",
" goals_home | \n",
" goals_away | \n",
" date_isolated | \n",
" time_isolated | \n",
" date_time_isolated | \n",
" date_time_timestamp | \n",
" date_date | \n",
" time_time | \n",
" full_fixture_date | \n",
" season | \n",
" teamIdNext | \n",
" teamNameNext | \n",
" fullNameNext | \n",
" player2player | \n",
" isPossessionRetained | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 8 | \n",
" Simple pass | \n",
" [{'id': 1801}] | \n",
" 134351 | \n",
" [{'y': 50, 'x': 50}, {'y': 57, 'x': 40}] | \n",
" 2499930 | \n",
" Pass | \n",
" 1659 | \n",
" 1H | \n",
" 1.914449 | \n",
" 85.0 | \n",
" 218431699 | \n",
" Played | \n",
" 4405654 | \n",
" 22 | \n",
" 181150 | \n",
" 2018-01-01 12:30:00 | \n",
" 0 | \n",
" The American Express Community Stadium | \n",
" 2499930 | \n",
" Brighton & Hove Albion - AFC Bournemouth, 2 - 2 | \n",
" January 1, 2018 at 1:30:00 PM GMT+1 | \n",
" [{'refereeId': 384965, 'role': 'referee'}, {'r... | \n",
" Regular | \n",
" 364 | \n",
" Premier League | \n",
" 364 | \n",
" England | \n",
" 78 | \n",
" Benik | \n",
" NaN | \n",
" Afobe | \n",
" 1993-02-12 | \n",
" 183 | \n",
" 134351 | \n",
" right | \n",
" B. Afobe | \n",
" Congo DR | \n",
" Forward | \n",
" England | \n",
" Benik Afobe | \n",
" AFC Bournemouth | \n",
" 1659 | \n",
" Brighton & Hove Albion - AFC Bournemouth | \n",
" 2 - 2 | \n",
" Brighton & Hove Albion | \n",
" AFC Bournemouth | \n",
" 2 | \n",
" 2 | \n",
" January 1, 2018 | \n",
" 1:30:00 PM GMT+1 | \n",
" January 1, 2018 1:30:00 PM | \n",
" 2018-01-01 13:30:00 | \n",
" 01-01-2018 | \n",
" 13:30:00 | \n",
" 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... | \n",
" 17/18 | \n",
" 1659.0 | \n",
" AFC Bournemouth | \n",
" Lewis Cook | \n",
" Benik Afobe - Lewis Cook | \n",
" True | \n",
"
\n",
" \n",
" 1 | \n",
" 8 | \n",
" Simple pass | \n",
" [{'id': 1801}] | \n",
" 302518 | \n",
" [{'y': 57, 'x': 40}, {'y': 12, 'x': 33}] | \n",
" 2499930 | \n",
" Pass | \n",
" 1659 | \n",
" 1H | \n",
" 2.784230 | \n",
" 85.0 | \n",
" 218431700 | \n",
" Played | \n",
" 4405654 | \n",
" 22 | \n",
" 181150 | \n",
" 2018-01-01 12:30:00 | \n",
" 0 | \n",
" The American Express Community Stadium | \n",
" 2499930 | \n",
" Brighton & Hove Albion - AFC Bournemouth, 2 - 2 | \n",
" January 1, 2018 at 1:30:00 PM GMT+1 | \n",
" [{'refereeId': 384965, 'role': 'referee'}, {'r... | \n",
" Regular | \n",
" 364 | \n",
" Premier League | \n",
" 364 | \n",
" England | \n",
" 71 | \n",
" Lewis | \n",
" NaN | \n",
" Cook | \n",
" 1997-02-03 | \n",
" 175 | \n",
" 302518 | \n",
" right | \n",
" L. Cook | \n",
" England | \n",
" Midfielder | \n",
" England | \n",
" Lewis Cook | \n",
" AFC Bournemouth | \n",
" 1659 | \n",
" Brighton & Hove Albion - AFC Bournemouth | \n",
" 2 - 2 | \n",
" Brighton & Hove Albion | \n",
" AFC Bournemouth | \n",
" 2 | \n",
" 2 | \n",
" January 1, 2018 | \n",
" 1:30:00 PM GMT+1 | \n",
" January 1, 2018 1:30:00 PM | \n",
" 2018-01-01 13:30:00 | \n",
" 01-01-2018 | \n",
" 13:30:00 | \n",
" 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... | \n",
" 17/18 | \n",
" 1659.0 | \n",
" AFC Bournemouth | \n",
" Charlie Daniels | \n",
" Lewis Cook - Charlie Daniels | \n",
" True | \n",
"
\n",
" \n",
" 2 | \n",
" 8 | \n",
" Simple pass | \n",
" [{'id': 1801}] | \n",
" 9285 | \n",
" [{'y': 12, 'x': 33}, {'y': 4, 'x': 38}] | \n",
" 2499930 | \n",
" Pass | \n",
" 1659 | \n",
" 1H | \n",
" 5.040106 | \n",
" 85.0 | \n",
" 218431701 | \n",
" Played | \n",
" 4405654 | \n",
" 22 | \n",
" 181150 | \n",
" 2018-01-01 12:30:00 | \n",
" 0 | \n",
" The American Express Community Stadium | \n",
" 2499930 | \n",
" Brighton & Hove Albion - AFC Bournemouth, 2 - 2 | \n",
" January 1, 2018 at 1:30:00 PM GMT+1 | \n",
" [{'refereeId': 384965, 'role': 'referee'}, {'r... | \n",
" Regular | \n",
" 364 | \n",
" Premier League | \n",
" 364 | \n",
" England | \n",
" 75 | \n",
" Charlie | \n",
" NaN | \n",
" Daniels | \n",
" 1986-09-07 | \n",
" 178 | \n",
" 9285 | \n",
" left | \n",
" C. Daniels | \n",
" England | \n",
" Defender | \n",
" England | \n",
" Charlie Daniels | \n",
" AFC Bournemouth | \n",
" 1659 | \n",
" Brighton & Hove Albion - AFC Bournemouth | \n",
" 2 - 2 | \n",
" Brighton & Hove Albion | \n",
" AFC Bournemouth | \n",
" 2 | \n",
" 2 | \n",
" January 1, 2018 | \n",
" 1:30:00 PM GMT+1 | \n",
" January 1, 2018 1:30:00 PM | \n",
" 2018-01-01 13:30:00 | \n",
" 01-01-2018 | \n",
" 13:30:00 | \n",
" 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... | \n",
" 17/18 | \n",
" 1659.0 | \n",
" AFC Bournemouth | \n",
" Marc Pugh | \n",
" Charlie Daniels - Marc Pugh | \n",
" True | \n",
"
\n",
" \n",
" 3 | \n",
" 8 | \n",
" Simple pass | \n",
" [{'id': 1801}] | \n",
" 9293 | \n",
" [{'y': 4, 'x': 38}, {'y': 26, 'x': 41}] | \n",
" 2499930 | \n",
" Pass | \n",
" 1659 | \n",
" 1H | \n",
" 6.544869 | \n",
" 85.0 | \n",
" 218431702 | \n",
" Played | \n",
" 4405654 | \n",
" 22 | \n",
" 181150 | \n",
" 2018-01-01 12:30:00 | \n",
" 0 | \n",
" The American Express Community Stadium | \n",
" 2499930 | \n",
" Brighton & Hove Albion - AFC Bournemouth, 2 - 2 | \n",
" January 1, 2018 at 1:30:00 PM GMT+1 | \n",
" [{'refereeId': 384965, 'role': 'referee'}, {'r... | \n",
" Regular | \n",
" 364 | \n",
" Premier League | \n",
" 364 | \n",
" England | \n",
" 72 | \n",
" Marc | \n",
" NaN | \n",
" Pugh | \n",
" 1987-04-02 | \n",
" 180 | \n",
" 9293 | \n",
" right | \n",
" M. Pugh | \n",
" England | \n",
" Midfielder | \n",
" England | \n",
" Marc Pugh | \n",
" AFC Bournemouth | \n",
" 1659 | \n",
" Brighton & Hove Albion - AFC Bournemouth | \n",
" 2 - 2 | \n",
" Brighton & Hove Albion | \n",
" AFC Bournemouth | \n",
" 2 | \n",
" 2 | \n",
" January 1, 2018 | \n",
" 1:30:00 PM GMT+1 | \n",
" January 1, 2018 1:30:00 PM | \n",
" 2018-01-01 13:30:00 | \n",
" 01-01-2018 | \n",
" 13:30:00 | \n",
" 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... | \n",
" 17/18 | \n",
" 1659.0 | \n",
" AFC Bournemouth | \n",
" Harry Arter | \n",
" Marc Pugh - Harry Arter | \n",
" True | \n",
"
\n",
" \n",
" 4 | \n",
" 8 | \n",
" Simple pass | \n",
" [{'id': 1801}] | \n",
" 9283 | \n",
" [{'y': 26, 'x': 41}, {'y': 10, 'x': 53}] | \n",
" 2499930 | \n",
" Pass | \n",
" 1659 | \n",
" 1H | \n",
" 8.245745 | \n",
" 85.0 | \n",
" 218431703 | \n",
" Played | \n",
" 4405654 | \n",
" 22 | \n",
" 181150 | \n",
" 2018-01-01 12:30:00 | \n",
" 0 | \n",
" The American Express Community Stadium | \n",
" 2499930 | \n",
" Brighton & Hove Albion - AFC Bournemouth, 2 - 2 | \n",
" January 1, 2018 at 1:30:00 PM GMT+1 | \n",
" [{'refereeId': 384965, 'role': 'referee'}, {'r... | \n",
" Regular | \n",
" 364 | \n",
" Premier League | \n",
" 364 | \n",
" England | \n",
" 70 | \n",
" Harry | \n",
" NaN | \n",
" Arter | \n",
" 1989-12-28 | \n",
" 178 | \n",
" 9283 | \n",
" right | \n",
" H. Arter | \n",
" Ireland Republic | \n",
" Midfielder | \n",
" England | \n",
" Harry Arter | \n",
" AFC Bournemouth | \n",
" 1659 | \n",
" Brighton & Hove Albion - AFC Bournemouth | \n",
" 2 - 2 | \n",
" Brighton & Hove Albion | \n",
" AFC Bournemouth | \n",
" 2 | \n",
" 2 | \n",
" January 1, 2018 | \n",
" 1:30:00 PM GMT+1 | \n",
" January 1, 2018 1:30:00 PM | \n",
" 2018-01-01 13:30:00 | \n",
" 01-01-2018 | \n",
" 13:30:00 | \n",
" 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... | \n",
" 17/18 | \n",
" 1659.0 | \n",
" AFC Bournemouth | \n",
" Marc Pugh | \n",
" Harry Arter - Marc Pugh | \n",
" True | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" eventId subEventName tags playerId \\\n",
"0 8 Simple pass [{'id': 1801}] 134351 \n",
"1 8 Simple pass [{'id': 1801}] 302518 \n",
"2 8 Simple pass [{'id': 1801}] 9285 \n",
"3 8 Simple pass [{'id': 1801}] 9293 \n",
"4 8 Simple pass [{'id': 1801}] 9283 \n",
"\n",
" positions matchId eventName teamId \\\n",
"0 [{'y': 50, 'x': 50}, {'y': 57, 'x': 40}] 2499930 Pass 1659 \n",
"1 [{'y': 57, 'x': 40}, {'y': 12, 'x': 33}] 2499930 Pass 1659 \n",
"2 [{'y': 12, 'x': 33}, {'y': 4, 'x': 38}] 2499930 Pass 1659 \n",
"3 [{'y': 4, 'x': 38}, {'y': 26, 'x': 41}] 2499930 Pass 1659 \n",
"4 [{'y': 26, 'x': 41}, {'y': 10, 'x': 53}] 2499930 Pass 1659 \n",
"\n",
" matchPeriod eventSec subEventId id status roundId gameweek \\\n",
"0 1H 1.914449 85.0 218431699 Played 4405654 22 \n",
"1 1H 2.784230 85.0 218431700 Played 4405654 22 \n",
"2 1H 5.040106 85.0 218431701 Played 4405654 22 \n",
"3 1H 6.544869 85.0 218431702 Played 4405654 22 \n",
"4 1H 8.245745 85.0 218431703 Played 4405654 22 \n",
"\n",
" seasonId dateutc winner \\\n",
"0 181150 2018-01-01 12:30:00 0 \n",
"1 181150 2018-01-01 12:30:00 0 \n",
"2 181150 2018-01-01 12:30:00 0 \n",
"3 181150 2018-01-01 12:30:00 0 \n",
"4 181150 2018-01-01 12:30:00 0 \n",
"\n",
" venue wyId_x \\\n",
"0 The American Express Community Stadium 2499930 \n",
"1 The American Express Community Stadium 2499930 \n",
"2 The American Express Community Stadium 2499930 \n",
"3 The American Express Community Stadium 2499930 \n",
"4 The American Express Community Stadium 2499930 \n",
"\n",
" label \\\n",
"0 Brighton & Hove Albion - AFC Bournemouth, 2 - 2 \n",
"1 Brighton & Hove Albion - AFC Bournemouth, 2 - 2 \n",
"2 Brighton & Hove Albion - AFC Bournemouth, 2 - 2 \n",
"3 Brighton & Hove Albion - AFC Bournemouth, 2 - 2 \n",
"4 Brighton & Hove Albion - AFC Bournemouth, 2 - 2 \n",
"\n",
" date \\\n",
"0 January 1, 2018 at 1:30:00 PM GMT+1 \n",
"1 January 1, 2018 at 1:30:00 PM GMT+1 \n",
"2 January 1, 2018 at 1:30:00 PM GMT+1 \n",
"3 January 1, 2018 at 1:30:00 PM GMT+1 \n",
"4 January 1, 2018 at 1:30:00 PM GMT+1 \n",
"\n",
" referees duration competitionId \\\n",
"0 [{'refereeId': 384965, 'role': 'referee'}, {'r... Regular 364 \n",
"1 [{'refereeId': 384965, 'role': 'referee'}, {'r... Regular 364 \n",
"2 [{'refereeId': 384965, 'role': 'referee'}, {'r... Regular 364 \n",
"3 [{'refereeId': 384965, 'role': 'referee'}, {'r... Regular 364 \n",
"4 [{'refereeId': 384965, 'role': 'referee'}, {'r... Regular 364 \n",
"\n",
" league_name wyId_y country weight firstName middleName lastName \\\n",
"0 Premier League 364 England 78 Benik NaN Afobe \n",
"1 Premier League 364 England 71 Lewis NaN Cook \n",
"2 Premier League 364 England 75 Charlie NaN Daniels \n",
"3 Premier League 364 England 72 Marc NaN Pugh \n",
"4 Premier League 364 England 70 Harry NaN Arter \n",
"\n",
" birthDate height wyId_x.1 foot shortName passportArea.name \\\n",
"0 1993-02-12 183 134351 right B. Afobe Congo DR \n",
"1 1997-02-03 175 302518 right L. Cook England \n",
"2 1986-09-07 178 9285 left C. Daniels England \n",
"3 1987-04-02 180 9293 right M. Pugh England \n",
"4 1989-12-28 178 9283 right H. Arter Ireland Republic \n",
"\n",
" role.name birthArea.name fullName teamName wyId_y.1 \\\n",
"0 Forward England Benik Afobe AFC Bournemouth 1659 \n",
"1 Midfielder England Lewis Cook AFC Bournemouth 1659 \n",
"2 Defender England Charlie Daniels AFC Bournemouth 1659 \n",
"3 Midfielder England Marc Pugh AFC Bournemouth 1659 \n",
"4 Midfielder England Harry Arter AFC Bournemouth 1659 \n",
"\n",
" fixture score_home_away \\\n",
"0 Brighton & Hove Albion - AFC Bournemouth 2 - 2 \n",
"1 Brighton & Hove Albion - AFC Bournemouth 2 - 2 \n",
"2 Brighton & Hove Albion - AFC Bournemouth 2 - 2 \n",
"3 Brighton & Hove Albion - AFC Bournemouth 2 - 2 \n",
"4 Brighton & Hove Albion - AFC Bournemouth 2 - 2 \n",
"\n",
" team_home team_away goals_home goals_away \\\n",
"0 Brighton & Hove Albion AFC Bournemouth 2 2 \n",
"1 Brighton & Hove Albion AFC Bournemouth 2 2 \n",
"2 Brighton & Hove Albion AFC Bournemouth 2 2 \n",
"3 Brighton & Hove Albion AFC Bournemouth 2 2 \n",
"4 Brighton & Hove Albion AFC Bournemouth 2 2 \n",
"\n",
" date_isolated time_isolated date_time_isolated \\\n",
"0 January 1, 2018 1:30:00 PM GMT+1 January 1, 2018 1:30:00 PM \n",
"1 January 1, 2018 1:30:00 PM GMT+1 January 1, 2018 1:30:00 PM \n",
"2 January 1, 2018 1:30:00 PM GMT+1 January 1, 2018 1:30:00 PM \n",
"3 January 1, 2018 1:30:00 PM GMT+1 January 1, 2018 1:30:00 PM \n",
"4 January 1, 2018 1:30:00 PM GMT+1 January 1, 2018 1:30:00 PM \n",
"\n",
" date_time_timestamp date_date time_time \\\n",
"0 2018-01-01 13:30:00 01-01-2018 13:30:00 \n",
"1 2018-01-01 13:30:00 01-01-2018 13:30:00 \n",
"2 2018-01-01 13:30:00 01-01-2018 13:30:00 \n",
"3 2018-01-01 13:30:00 01-01-2018 13:30:00 \n",
"4 2018-01-01 13:30:00 01-01-2018 13:30:00 \n",
"\n",
" full_fixture_date season teamIdNext \\\n",
"0 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... 17/18 1659.0 \n",
"1 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... 17/18 1659.0 \n",
"2 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... 17/18 1659.0 \n",
"3 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... 17/18 1659.0 \n",
"4 01-01-2018 Brighton & Hove Albion 2 v 2 AFC ... 17/18 1659.0 \n",
"\n",
" teamNameNext fullNameNext player2player \\\n",
"0 AFC Bournemouth Lewis Cook Benik Afobe - Lewis Cook \n",
"1 AFC Bournemouth Charlie Daniels Lewis Cook - Charlie Daniels \n",
"2 AFC Bournemouth Marc Pugh Charlie Daniels - Marc Pugh \n",
"3 AFC Bournemouth Harry Arter Marc Pugh - Harry Arter \n",
"4 AFC Bournemouth Marc Pugh Harry Arter - Marc Pugh \n",
"\n",
" isPossessionRetained \n",
"0 True \n",
"1 True \n",
"2 True \n",
"3 True \n",
"4 True "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Display the first 5 rows of the raw DataFrame, df_wyscout\n",
"df_wyscout.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(2845357, 62)\n"
]
}
],
"source": [
"# Print the shape of the raw DataFrame, ddf_wyscout_raw\n",
"print(df_wyscout.shape)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['eventId',\n",
" 'subEventName',\n",
" 'tags',\n",
" 'playerId',\n",
" 'positions',\n",
" 'matchId',\n",
" 'eventName',\n",
" 'teamId',\n",
" 'matchPeriod',\n",
" 'eventSec',\n",
" 'subEventId',\n",
" 'id',\n",
" 'status',\n",
" 'roundId',\n",
" 'gameweek',\n",
" 'seasonId',\n",
" 'dateutc',\n",
" 'winner',\n",
" 'venue',\n",
" 'wyId_x',\n",
" 'label',\n",
" 'date',\n",
" 'referees',\n",
" 'duration',\n",
" 'competitionId',\n",
" 'league_name',\n",
" 'wyId_y',\n",
" 'country',\n",
" 'weight',\n",
" 'firstName',\n",
" 'middleName',\n",
" 'lastName',\n",
" 'birthDate',\n",
" 'height',\n",
" 'wyId_x.1',\n",
" 'foot',\n",
" 'shortName',\n",
" 'passportArea.name',\n",
" 'role.name',\n",
" 'birthArea.name',\n",
" 'fullName',\n",
" 'teamName',\n",
" 'wyId_y.1',\n",
" 'fixture',\n",
" 'score_home_away',\n",
" 'team_home',\n",
" 'team_away',\n",
" 'goals_home',\n",
" 'goals_away',\n",
" 'date_isolated',\n",
" 'time_isolated',\n",
" 'date_time_isolated',\n",
" 'date_time_timestamp',\n",
" 'date_date',\n",
" 'time_time',\n",
" 'full_fixture_date',\n",
" 'season',\n",
" 'teamIdNext',\n",
" 'teamNameNext',\n",
" 'fullNameNext',\n",
" 'player2player',\n",
" 'isPossessionRetained']"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Display all column names\n",
"list(df_wyscout.columns)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"eventId int64\n",
"subEventName object\n",
"tags object\n",
"playerId int64\n",
"positions object\n",
"matchId int64\n",
"eventName object\n",
"teamId int64\n",
"matchPeriod object\n",
"eventSec float64\n",
"subEventId float64\n",
"id int64\n",
"status object\n",
"roundId int64\n",
"gameweek int64\n",
"seasonId int64\n",
"dateutc object\n",
"winner int64\n",
"venue object\n",
"wyId_x int64\n",
"label object\n",
"date object\n",
"referees object\n",
"duration object\n",
"competitionId int64\n",
"league_name object\n",
"wyId_y int64\n",
"country object\n",
"weight int64\n",
"firstName object\n",
"middleName float64\n",
"lastName object\n",
"birthDate object\n",
"height int64\n",
"wyId_x.1 int64\n",
"foot object\n",
"shortName object\n",
"passportArea.name object\n",
"role.name object\n",
"birthArea.name object\n",
"fullName object\n",
"teamName object\n",
"wyId_y.1 int64\n",
"fixture object\n",
"score_home_away object\n",
"team_home object\n",
"team_away object\n",
"goals_home int64\n",
"goals_away int64\n",
"date_isolated object\n",
"time_isolated object\n",
"date_time_isolated object\n",
"date_time_timestamp object\n",
"date_date object\n",
"time_time object\n",
"full_fixture_date object\n",
"season object\n",
"teamIdNext float64\n",
"teamNameNext object\n",
"fullNameNext object\n",
"player2player object\n",
"isPossessionRetained bool\n",
"dtype: object\n"
]
}
],
"source": [
"# Data types of the features of the raw DataFrame, df_raw\n",
"with pd.option_context('display.max_rows', None, 'display.max_columns', None):\n",
" print(df_wyscout.dtypes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4.8. Aggregate Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4.8.1. Fixture Level"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:20: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n"
]
}
],
"source": [
"# Select columns of interest\n",
"\n",
"## Define columns\n",
"cols = ['date_time_timestamp',\n",
" 'league_name',\n",
" 'fixture',\n",
" 'team_home',\n",
" 'team_away',\n",
" 'teamName',\n",
" 'goals_home',\n",
" 'goals_away',\n",
" 'eventName',\n",
" 'subEventName'\n",
" ]\n",
"\n",
"##\n",
"df_wyscout_select = df_wyscout[cols]\n",
"\n",
"##\n",
"df_wyscout_select['Opponent'] = np.where(df_wyscout_select['team_home'] == df_wyscout_select['teamName'], df_wyscout_select['team_away'], df_wyscout_select['team_home'])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Date | \n",
" League_Name | \n",
" Fixture | \n",
" Team | \n",
" Opponent | \n",
" Goals_Home | \n",
" Goals_Away | \n",
" Event | \n",
" SubEvent | \n",
" Team_Value | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" Air duel | \n",
" 67 | \n",
"
\n",
" \n",
" 1 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" Ground attacking duel | \n",
" 75 | \n",
"
\n",
" \n",
" 2 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" Ground defending duel | \n",
" 49 | \n",
"
\n",
" \n",
" 3 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" Ground loose ball duel | \n",
" 29 | \n",
"
\n",
" \n",
" 4 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Foul | \n",
" Foul | \n",
" 12 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Date League_Name Fixture Team Opponent \\\n",
"0 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"1 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"2 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"3 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"4 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"\n",
" Goals_Home Goals_Away Event SubEvent Team_Value \n",
"0 3 2 Duel Air duel 67 \n",
"1 3 2 Duel Ground attacking duel 75 \n",
"2 3 2 Duel Ground defending duel 49 \n",
"3 3 2 Duel Ground loose ball duel 29 \n",
"4 3 2 Foul Foul 12 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped = (df_wyscout_select\n",
" #.groupby(['full_fixture_date'])\n",
" .groupby(['date_time_timestamp',\n",
" 'league_name',\n",
" 'fixture',\n",
" 'teamName',\n",
" 'Opponent',\n",
" 'goals_home',\n",
" 'goals_away',\n",
" 'eventName',\n",
" 'subEventName'])\n",
" .agg({'eventName': ['count']},\n",
" {'subEventName': ['count']}\n",
" )\n",
" )\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped.columns = df_wyscout_fixture_grouped.columns.droplevel(level=0)\n",
"\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped = df_wyscout_fixture_grouped.reset_index()\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped = df_wyscout_fixture_grouped.rename(columns={'date_time_timestamp': 'Date',\n",
" 'league_name': 'League_Name',\n",
" 'fixture': 'Fixture',\n",
" 'teamName': 'Team',\n",
" 'Opponent': 'Opponent',\n",
" 'goals_home': 'Goals_Home',\n",
" 'goals_away': 'Goals_Away',\n",
" 'eventName': 'Event',\n",
" 'subEventName': 'SubEvent',\n",
" 'count': 'Team_Value'\n",
" }\n",
" )\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped.head()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Duel', 'Foul', 'Free Kick', 'Goalkeeper leaving line',\n",
" 'Others on the ball', 'Pass', 'Save attempt', 'Shot',\n",
" 'Interruption'], dtype=object)"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# List unique values in the df_wyscout_fixture_grouped['Event_Name'] column\n",
"df_wyscout_fixture_grouped.Event.unique()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Air duel', 'Ground attacking duel', 'Ground defending duel',\n",
" 'Ground loose ball duel', 'Foul', 'Corner', 'Free Kick',\n",
" 'Free kick cross', 'Free kick shot', 'Goal kick', 'Throw in',\n",
" 'Goalkeeper leaving line', 'Acceleration', 'Clearance', 'Touch',\n",
" 'Cross', 'Hand pass', 'Head pass', 'High pass', 'Launch',\n",
" 'Simple pass', 'Smart pass', 'Reflexes', 'Save attempt', 'Shot',\n",
" 'Hand foul', 'Penalty', 'Out of game foul', 'Protest',\n",
" 'Simulation', 'Late card foul', 'Time lost foul', 'Violent Foul',\n",
" 'Ball out of the field', 'Whistle'], dtype=object)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# List unique values in the df_wyscout_fixture_grouped['SubEvent_Name'] column\n",
"df_wyscout_fixture_grouped.SubEvent.unique()"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"# Select columns of interest\n",
"\n",
"## Define columns\n",
"cols = ['Date',\n",
" 'League_Name',\n",
" 'Fixture',\n",
" 'Team',\n",
" 'Opponent',\n",
" 'Event',\n",
" 'SubEvent_Name',\n",
" 'Team_Value'\n",
" ]\n",
"\n",
"##\n",
"df_wyscout_fixture_grouped_select = df_wyscout_fixture_grouped[cols]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"# Join DataFrame to itself on 'Date', 'Fixture', 'Team'/'Opponent', and 'Event', to join Team and Opponent together\n",
"df_wyscout_fixture_grouped = pd.merge(df_wyscout_fixture_grouped, df_wyscout_fixture_grouped, how='left', left_on=['Date', 'League_Name', 'Fixture', 'Opponent', 'Event'], right_on = ['Date', 'League_Name', 'Fixture', 'Team', 'Event'])"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Date | \n",
" League_Name | \n",
" Fixture | \n",
" Team_x | \n",
" Opponent_x | \n",
" Goals_Home_x | \n",
" Goals_Away_x | \n",
" Event | \n",
" Team_Value_x | \n",
" Team_y | \n",
" Opponent_y | \n",
" Goals_Home_y | \n",
" Goals_Away_y | \n",
" Team_Value_y | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" 220 | \n",
" Toulouse | \n",
" Monaco | \n",
" 3.0 | \n",
" 2.0 | \n",
" 205.0 | \n",
"
\n",
" \n",
" 1 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Foul | \n",
" 12 | \n",
" Toulouse | \n",
" Monaco | \n",
" 3.0 | \n",
" 2.0 | \n",
" 23.0 | \n",
"
\n",
" \n",
" 2 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Free Kick | \n",
" 58 | \n",
" Toulouse | \n",
" Monaco | \n",
" 3.0 | \n",
" 2.0 | \n",
" 47.0 | \n",
"
\n",
" \n",
" 3 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 4 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Offside | \n",
" 5 | \n",
" Toulouse | \n",
" Monaco | \n",
" 3.0 | \n",
" 2.0 | \n",
" 1.0 | \n",
"
\n",
" \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
" ... | \n",
"
\n",
" \n",
" 24763 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Offside | \n",
" 3 | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1.0 | \n",
" 0.0 | \n",
" 3.0 | \n",
"
\n",
" \n",
" 24764 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Others on the ball | \n",
" 81 | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1.0 | \n",
" 0.0 | \n",
" 95.0 | \n",
"
\n",
" \n",
" 24765 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Pass | \n",
" 360 | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1.0 | \n",
" 0.0 | \n",
" 592.0 | \n",
"
\n",
" \n",
" 24766 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Save attempt | \n",
" 4 | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1.0 | \n",
" 0.0 | \n",
" 2.0 | \n",
"
\n",
" \n",
" 24767 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Shot | \n",
" 12 | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1.0 | \n",
" 0.0 | \n",
" 10.0 | \n",
"
\n",
" \n",
"
\n",
"
24768 rows × 14 columns
\n",
"
"
],
"text/plain": [
" Date League_Name Fixture \\\n",
"0 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse \n",
"1 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse \n",
"2 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse \n",
"3 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse \n",
"4 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse \n",
"... ... ... ... \n",
"24763 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24764 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24765 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24766 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24767 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"\n",
" Team_x Opponent_x Goals_Home_x Goals_Away_x \\\n",
"0 Monaco Toulouse 3 2 \n",
"1 Monaco Toulouse 3 2 \n",
"2 Monaco Toulouse 3 2 \n",
"3 Monaco Toulouse 3 2 \n",
"4 Monaco Toulouse 3 2 \n",
"... ... ... ... ... \n",
"24763 Real Sociedad Barcelona 1 0 \n",
"24764 Real Sociedad Barcelona 1 0 \n",
"24765 Real Sociedad Barcelona 1 0 \n",
"24766 Real Sociedad Barcelona 1 0 \n",
"24767 Real Sociedad Barcelona 1 0 \n",
"\n",
" Event Team_Value_x Team_y Opponent_y \\\n",
"0 Duel 220 Toulouse Monaco \n",
"1 Foul 12 Toulouse Monaco \n",
"2 Free Kick 58 Toulouse Monaco \n",
"3 Goalkeeper leaving line 2 NaN NaN \n",
"4 Offside 5 Toulouse Monaco \n",
"... ... ... ... ... \n",
"24763 Offside 3 Barcelona Real Sociedad \n",
"24764 Others on the ball 81 Barcelona Real Sociedad \n",
"24765 Pass 360 Barcelona Real Sociedad \n",
"24766 Save attempt 4 Barcelona Real Sociedad \n",
"24767 Shot 12 Barcelona Real Sociedad \n",
"\n",
" Goals_Home_y Goals_Away_y Team_Value_y \n",
"0 3.0 2.0 205.0 \n",
"1 3.0 2.0 23.0 \n",
"2 3.0 2.0 47.0 \n",
"3 NaN NaN NaN \n",
"4 3.0 2.0 1.0 \n",
"... ... ... ... \n",
"24763 1.0 0.0 3.0 \n",
"24764 1.0 0.0 95.0 \n",
"24765 1.0 0.0 592.0 \n",
"24766 1.0 0.0 2.0 \n",
"24767 1.0 0.0 10.0 \n",
"\n",
"[24768 rows x 14 columns]"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_wyscout_fixture_grouped"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Date | \n",
" League_Name | \n",
" Fixture | \n",
" Team | \n",
" Opponent | \n",
" Goals_Home | \n",
" Goals_Away | \n",
" Event | \n",
" Team_Value | \n",
" Opponent_Value | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" 220 | \n",
" 205 | \n",
"
\n",
" \n",
" 1 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Foul | \n",
" 12 | \n",
" 23 | \n",
"
\n",
" \n",
" 2 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Free Kick | \n",
" 58 | \n",
" 47 | \n",
"
\n",
" \n",
" 3 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" 0 | \n",
"
\n",
" \n",
" 4 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Offside | \n",
" 5 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Date League_Name Fixture Team Opponent \\\n",
"0 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"1 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"2 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"3 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"4 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"\n",
" Goals_Home Goals_Away Event Team_Value Opponent_Value \n",
"0 3 2 Duel 220 205 \n",
"1 3 2 Foul 12 23 \n",
"2 3 2 Free Kick 58 47 \n",
"3 3 2 Goalkeeper leaving line 2 0 \n",
"4 3 2 Offside 5 1 "
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Clean Data\n",
"\n",
"## Drop columns\n",
"df_wyscout_fixture_grouped = df_wyscout_fixture_grouped.drop(columns=['Team_y', 'Opponent_y', 'Goals_Home_y', 'Goals_Away_y'])\n",
"\n",
"## Rename columns\n",
"df_wyscout_fixture_grouped = df_wyscout_fixture_grouped.rename(columns={'Team_x': 'Team',\n",
" 'Opponent_x': 'Opponent',\n",
" 'Goals_Home_x': 'Goals_Home',\n",
" 'Goals_Away_x': 'Goals_Away',\n",
" 'Team_Value_x': 'Team_Value',\n",
" 'Team_Value_y': 'Opponent_Value',\n",
" }\n",
" )\n",
"\n",
"## Replace null values with zeros\n",
"df_wyscout_fixture_grouped['Team_Value'] = df_wyscout_fixture_grouped['Team_Value'].replace(np.nan, 0)\n",
"df_wyscout_fixture_grouped['Opponent_Value'] = df_wyscout_fixture_grouped['Opponent_Value'].replace(np.nan, 0)\n",
"\n",
"## Convert Opponent_Value' from Float64 to Int64 type\n",
"df_wyscout_fixture_grouped['Opponent_Value'] = df_wyscout_fixture_grouped['Opponent_Value'].astype('Int64')\n",
"\n",
"## Display DataFrame\n",
"df_wyscout_fixture_grouped.head()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Team | \n",
" Date | \n",
" Gameweek | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" AFC Bournemouth | \n",
" 2017-08-12 16:00:00 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" AFC Bournemouth | \n",
" 2017-08-19 16:00:00 | \n",
" 2 | \n",
"
\n",
" \n",
" 2 | \n",
" AFC Bournemouth | \n",
" 2017-08-26 13:30:00 | \n",
" 3 | \n",
"
\n",
" \n",
" 3 | \n",
" AFC Bournemouth | \n",
" 2017-09-09 16:00:00 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" AFC Bournemouth | \n",
" 2017-09-15 21:00:00 | \n",
" 5 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Team Date Gameweek\n",
"0 AFC Bournemouth 2017-08-12 16:00:00 1\n",
"1 AFC Bournemouth 2017-08-19 16:00:00 2\n",
"2 AFC Bournemouth 2017-08-26 13:30:00 3\n",
"3 AFC Bournemouth 2017-09-09 16:00:00 4\n",
"4 AFC Bournemouth 2017-09-15 21:00:00 5"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#\n",
"\n",
"##\n",
"df_fixture_gw = (df_wyscout_fixture_grouped\n",
" .groupby(['Date', 'Team'])\n",
" .agg({'Team': ['nunique']})\n",
" )\n",
"\n",
"##\n",
"df_fixture_gw.columns = df_fixture_gw.columns.droplevel(level=0)\n",
"\n",
"\n",
"##\n",
"df_fixture_gw = df_fixture_gw.reset_index()\n",
"\n",
"##\n",
"df_fixture_gw = df_fixture_gw.rename(columns={'Date': 'Date',\n",
" 'nunique': 'Gameweek',\n",
" }\n",
" )\n",
"\n",
"## Groupby. See: https://stackoverflow.com/questions/18554920/pandas-aggregate-count-distinct\n",
"df_fixture_gw = (df_fixture_gw.groupby(['Team', 'Date']).sum()\n",
" .groupby(level=0).cumsum().reset_index()\n",
" )\n",
"\n",
"## Display DataFrame\n",
"df_fixture_gw.head()"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Date | \n",
" League_Name | \n",
" Fixture | \n",
" Team | \n",
" Opponent | \n",
" Goals_Home | \n",
" Goals_Away | \n",
" Event | \n",
" Team_Value | \n",
" Opponent_Value | \n",
" Gameweek | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" 220 | \n",
" 205 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Foul | \n",
" 12 | \n",
" 23 | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Free Kick | \n",
" 58 | \n",
" 47 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Offside | \n",
" 5 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 5 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Others on the ball | \n",
" 46 | \n",
" 49 | \n",
" 1 | \n",
"
\n",
" \n",
" 6 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Pass | \n",
" 467 | \n",
" 170 | \n",
" 1 | \n",
"
\n",
" \n",
" 7 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Save attempt | \n",
" 4 | \n",
" 7 | \n",
" 1 | \n",
"
\n",
" \n",
" 8 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Monaco | \n",
" Toulouse | \n",
" 3 | \n",
" 2 | \n",
" Shot | \n",
" 12 | \n",
" 4 | \n",
" 1 | \n",
"
\n",
" \n",
" 9 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Duel | \n",
" 205 | \n",
" 220 | \n",
" 1 | \n",
"
\n",
" \n",
" 10 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Foul | \n",
" 23 | \n",
" 12 | \n",
" 1 | \n",
"
\n",
" \n",
" 11 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Free Kick | \n",
" 47 | \n",
" 58 | \n",
" 1 | \n",
"
\n",
" \n",
" 12 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Offside | \n",
" 1 | \n",
" 5 | \n",
" 1 | \n",
"
\n",
" \n",
" 13 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Others on the ball | \n",
" 49 | \n",
" 46 | \n",
" 1 | \n",
"
\n",
" \n",
" 14 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Pass | \n",
" 170 | \n",
" 467 | \n",
" 1 | \n",
"
\n",
" \n",
" 15 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Save attempt | \n",
" 7 | \n",
" 4 | \n",
" 1 | \n",
"
\n",
" \n",
" 16 | \n",
" 2017-08-04 20:45:00 | \n",
" Ligue 1 | \n",
" Monaco - Toulouse | \n",
" Toulouse | \n",
" Monaco | \n",
" 3 | \n",
" 2 | \n",
" Shot | \n",
" 4 | \n",
" 12 | \n",
" 1 | \n",
"
\n",
" \n",
" 17 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Duel | \n",
" 205 | \n",
" 192 | \n",
" 1 | \n",
"
\n",
" \n",
" 18 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Foul | \n",
" 12 | \n",
" 9 | \n",
" 1 | \n",
"
\n",
" \n",
" 19 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Free Kick | \n",
" 33 | \n",
" 41 | \n",
" 1 | \n",
"
\n",
" \n",
" 20 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Goalkeeper leaving line | \n",
" 1 | \n",
" 3 | \n",
" 1 | \n",
"
\n",
" \n",
" 21 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Others on the ball | \n",
" 82 | \n",
" 55 | \n",
" 1 | \n",
"
\n",
" \n",
" 22 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Pass | \n",
" 328 | \n",
" 724 | \n",
" 1 | \n",
"
\n",
" \n",
" 23 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Save attempt | \n",
" 5 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 24 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" Amiens SC | \n",
" PSG | \n",
" 2 | \n",
" 0 | \n",
" Shot | \n",
" 6 | \n",
" 15 | \n",
" 1 | \n",
"
\n",
" \n",
" 25 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Duel | \n",
" 192 | \n",
" 205 | \n",
" 1 | \n",
"
\n",
" \n",
" 26 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Foul | \n",
" 9 | \n",
" 12 | \n",
" 1 | \n",
"
\n",
" \n",
" 27 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Free Kick | \n",
" 41 | \n",
" 33 | \n",
" 1 | \n",
"
\n",
" \n",
" 28 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Goalkeeper leaving line | \n",
" 3 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 29 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Offside | \n",
" 3 | \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
" 30 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Others on the ball | \n",
" 55 | \n",
" 82 | \n",
" 1 | \n",
"
\n",
" \n",
" 31 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Pass | \n",
" 724 | \n",
" 328 | \n",
" 1 | \n",
"
\n",
" \n",
" 32 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Save attempt | \n",
" 1 | \n",
" 5 | \n",
" 1 | \n",
"
\n",
" \n",
" 33 | \n",
" 2017-08-05 17:15:00 | \n",
" Ligue 1 | \n",
" PSG - Amiens SC | \n",
" PSG | \n",
" Amiens SC | \n",
" 2 | \n",
" 0 | \n",
" Shot | \n",
" 15 | \n",
" 6 | \n",
" 1 | \n",
"
\n",
" \n",
" 34 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Duel | \n",
" 160 | \n",
" 168 | \n",
" 1 | \n",
"
\n",
" \n",
" 35 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Foul | \n",
" 12 | \n",
" 7 | \n",
" 1 | \n",
"
\n",
" \n",
" 36 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Free Kick | \n",
" 34 | \n",
" 51 | \n",
" 1 | \n",
"
\n",
" \n",
" 37 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Goalkeeper leaving line | \n",
" 4 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 38 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Offside | \n",
" 1 | \n",
" 3 | \n",
" 1 | \n",
"
\n",
" \n",
" 39 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Others on the ball | \n",
" 46 | \n",
" 44 | \n",
" 1 | \n",
"
\n",
" \n",
" 40 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Pass | \n",
" 396 | \n",
" 528 | \n",
" 1 | \n",
"
\n",
" \n",
" 41 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Save attempt | \n",
" 4 | \n",
" 5 | \n",
" 1 | \n",
"
\n",
" \n",
" 42 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Guingamp | \n",
" Metz | \n",
" 1 | \n",
" 3 | \n",
" Shot | \n",
" 8 | \n",
" 6 | \n",
" 1 | \n",
"
\n",
" \n",
" 43 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Duel | \n",
" 168 | \n",
" 160 | \n",
" 1 | \n",
"
\n",
" \n",
" 44 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Foul | \n",
" 7 | \n",
" 12 | \n",
" 1 | \n",
"
\n",
" \n",
" 45 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Free Kick | \n",
" 51 | \n",
" 34 | \n",
" 1 | \n",
"
\n",
" \n",
" 46 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Goalkeeper leaving line | \n",
" 1 | \n",
" 4 | \n",
" 1 | \n",
"
\n",
" \n",
" 47 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Offside | \n",
" 3 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 48 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Others on the ball | \n",
" 44 | \n",
" 46 | \n",
" 1 | \n",
"
\n",
" \n",
" 49 | \n",
" 2017-08-05 20:00:00 | \n",
" Ligue 1 | \n",
" Metz - Guingamp | \n",
" Metz | \n",
" Guingamp | \n",
" 1 | \n",
" 3 | \n",
" Pass | \n",
" 528 | \n",
" 396 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Date League_Name Fixture Team Opponent \\\n",
"0 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"1 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"2 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"3 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"4 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"5 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"6 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"7 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"8 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Monaco Toulouse \n",
"9 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"10 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"11 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"12 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"13 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"14 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"15 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"16 2017-08-04 20:45:00 Ligue 1 Monaco - Toulouse Toulouse Monaco \n",
"17 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"18 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"19 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"20 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"21 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"22 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"23 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"24 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC Amiens SC PSG \n",
"25 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"26 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"27 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"28 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"29 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"30 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"31 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"32 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"33 2017-08-05 17:15:00 Ligue 1 PSG - Amiens SC PSG Amiens SC \n",
"34 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"35 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"36 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"37 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"38 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"39 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"40 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"41 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"42 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Guingamp Metz \n",
"43 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"44 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"45 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"46 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"47 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"48 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"49 2017-08-05 20:00:00 Ligue 1 Metz - Guingamp Metz Guingamp \n",
"\n",
" Goals_Home Goals_Away Event Team_Value \\\n",
"0 3 2 Duel 220 \n",
"1 3 2 Foul 12 \n",
"2 3 2 Free Kick 58 \n",
"3 3 2 Goalkeeper leaving line 2 \n",
"4 3 2 Offside 5 \n",
"5 3 2 Others on the ball 46 \n",
"6 3 2 Pass 467 \n",
"7 3 2 Save attempt 4 \n",
"8 3 2 Shot 12 \n",
"9 3 2 Duel 205 \n",
"10 3 2 Foul 23 \n",
"11 3 2 Free Kick 47 \n",
"12 3 2 Offside 1 \n",
"13 3 2 Others on the ball 49 \n",
"14 3 2 Pass 170 \n",
"15 3 2 Save attempt 7 \n",
"16 3 2 Shot 4 \n",
"17 2 0 Duel 205 \n",
"18 2 0 Foul 12 \n",
"19 2 0 Free Kick 33 \n",
"20 2 0 Goalkeeper leaving line 1 \n",
"21 2 0 Others on the ball 82 \n",
"22 2 0 Pass 328 \n",
"23 2 0 Save attempt 5 \n",
"24 2 0 Shot 6 \n",
"25 2 0 Duel 192 \n",
"26 2 0 Foul 9 \n",
"27 2 0 Free Kick 41 \n",
"28 2 0 Goalkeeper leaving line 3 \n",
"29 2 0 Offside 3 \n",
"30 2 0 Others on the ball 55 \n",
"31 2 0 Pass 724 \n",
"32 2 0 Save attempt 1 \n",
"33 2 0 Shot 15 \n",
"34 1 3 Duel 160 \n",
"35 1 3 Foul 12 \n",
"36 1 3 Free Kick 34 \n",
"37 1 3 Goalkeeper leaving line 4 \n",
"38 1 3 Offside 1 \n",
"39 1 3 Others on the ball 46 \n",
"40 1 3 Pass 396 \n",
"41 1 3 Save attempt 4 \n",
"42 1 3 Shot 8 \n",
"43 1 3 Duel 168 \n",
"44 1 3 Foul 7 \n",
"45 1 3 Free Kick 51 \n",
"46 1 3 Goalkeeper leaving line 1 \n",
"47 1 3 Offside 3 \n",
"48 1 3 Others on the ball 44 \n",
"49 1 3 Pass 528 \n",
"\n",
" Opponent_Value Gameweek \n",
"0 205 1 \n",
"1 23 1 \n",
"2 47 1 \n",
"3 0 1 \n",
"4 1 1 \n",
"5 49 1 \n",
"6 170 1 \n",
"7 7 1 \n",
"8 4 1 \n",
"9 220 1 \n",
"10 12 1 \n",
"11 58 1 \n",
"12 5 1 \n",
"13 46 1 \n",
"14 467 1 \n",
"15 4 1 \n",
"16 12 1 \n",
"17 192 1 \n",
"18 9 1 \n",
"19 41 1 \n",
"20 3 1 \n",
"21 55 1 \n",
"22 724 1 \n",
"23 1 1 \n",
"24 15 1 \n",
"25 205 1 \n",
"26 12 1 \n",
"27 33 1 \n",
"28 1 1 \n",
"29 0 1 \n",
"30 82 1 \n",
"31 328 1 \n",
"32 5 1 \n",
"33 6 1 \n",
"34 168 1 \n",
"35 7 1 \n",
"36 51 1 \n",
"37 1 1 \n",
"38 3 1 \n",
"39 44 1 \n",
"40 528 1 \n",
"41 5 1 \n",
"42 6 1 \n",
"43 160 1 \n",
"44 12 1 \n",
"45 34 1 \n",
"46 4 1 \n",
"47 1 1 \n",
"48 46 1 \n",
"49 396 1 "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Join DataFrame \n",
"df_wyscout_fixture_grouped = pd.merge(df_wyscout_fixture_grouped, df_fixture_gw, how='left', left_on=['Date', 'Team'], right_on = ['Date', 'Team'])\n",
"\n",
"# Display DataFrame\n",
"df_wyscout_fixture_grouped.head(50)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Date | \n",
" League_Name | \n",
" Fixture | \n",
" Team | \n",
" Opponent | \n",
" Goals_Home | \n",
" Goals_Away | \n",
" Event | \n",
" Team_Value | \n",
" Opponent_Value | \n",
" Gameweek | \n",
"
\n",
" \n",
" \n",
" \n",
" 24718 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Free Kick | \n",
" 36 | \n",
" 39 | \n",
" 38 | \n",
"
\n",
" \n",
" 24719 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Goalkeeper leaving line | \n",
" 3 | \n",
" 2 | \n",
" 38 | \n",
"
\n",
" \n",
" 24720 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Offside | \n",
" 2 | \n",
" 5 | \n",
" 38 | \n",
"
\n",
" \n",
" 24721 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Others on the ball | \n",
" 67 | \n",
" 78 | \n",
" 38 | \n",
"
\n",
" \n",
" 24722 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Pass | \n",
" 512 | \n",
" 407 | \n",
" 38 | \n",
"
\n",
" \n",
" 24723 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Save attempt | \n",
" 4 | \n",
" 3 | \n",
" 38 | \n",
"
\n",
" \n",
" 24724 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Athletic Club | \n",
" Espanyol | \n",
" 0 | \n",
" 1 | \n",
" Shot | \n",
" 9 | \n",
" 12 | \n",
" 38 | \n",
"
\n",
" \n",
" 24725 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Duel | \n",
" 147 | \n",
" 154 | \n",
" 38 | \n",
"
\n",
" \n",
" 24726 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Foul | \n",
" 11 | \n",
" 4 | \n",
" 38 | \n",
"
\n",
" \n",
" 24727 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Free Kick | \n",
" 39 | \n",
" 36 | \n",
" 38 | \n",
"
\n",
" \n",
" 24728 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" 3 | \n",
" 38 | \n",
"
\n",
" \n",
" 24729 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Offside | \n",
" 5 | \n",
" 2 | \n",
" 38 | \n",
"
\n",
" \n",
" 24730 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Others on the ball | \n",
" 78 | \n",
" 67 | \n",
" 38 | \n",
"
\n",
" \n",
" 24731 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Pass | \n",
" 407 | \n",
" 512 | \n",
" 38 | \n",
"
\n",
" \n",
" 24732 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Save attempt | \n",
" 3 | \n",
" 4 | \n",
" 38 | \n",
"
\n",
" \n",
" 24733 | \n",
" 2018-05-20 16:15:00 | \n",
" La Liga | \n",
" Athletic Club - Espanyol | \n",
" Espanyol | \n",
" Athletic Club | \n",
" 0 | \n",
" 1 | \n",
" Shot | \n",
" 12 | \n",
" 9 | \n",
" 38 | \n",
"
\n",
" \n",
" 24734 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Duel | \n",
" 191 | \n",
" 181 | \n",
" 38 | \n",
"
\n",
" \n",
" 24735 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Foul | \n",
" 15 | \n",
" 13 | \n",
" 38 | \n",
"
\n",
" \n",
" 24736 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Free Kick | \n",
" 56 | \n",
" 34 | \n",
" 38 | \n",
"
\n",
" \n",
" 24737 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Offside | \n",
" 6 | \n",
" 0 | \n",
" 38 | \n",
"
\n",
" \n",
" 24738 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Others on the ball | \n",
" 56 | \n",
" 64 | \n",
" 38 | \n",
"
\n",
" \n",
" 24739 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Pass | \n",
" 428 | \n",
" 406 | \n",
" 38 | \n",
"
\n",
" \n",
" 24740 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Save attempt | \n",
" 6 | \n",
" 4 | \n",
" 38 | \n",
"
\n",
" \n",
" 24741 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" Eibar | \n",
" 2 | \n",
" 2 | \n",
" Shot | \n",
" 7 | \n",
" 16 | \n",
" 38 | \n",
"
\n",
" \n",
" 24742 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Duel | \n",
" 181 | \n",
" 191 | \n",
" 38 | \n",
"
\n",
" \n",
" 24743 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Foul | \n",
" 13 | \n",
" 15 | \n",
" 38 | \n",
"
\n",
" \n",
" 24744 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Free Kick | \n",
" 34 | \n",
" 56 | \n",
" 38 | \n",
"
\n",
" \n",
" 24745 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" 0 | \n",
" 38 | \n",
"
\n",
" \n",
" 24746 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Others on the ball | \n",
" 64 | \n",
" 56 | \n",
" 38 | \n",
"
\n",
" \n",
" 24747 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Pass | \n",
" 406 | \n",
" 428 | \n",
" 38 | \n",
"
\n",
" \n",
" 24748 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Save attempt | \n",
" 4 | \n",
" 6 | \n",
" 38 | \n",
"
\n",
" \n",
" 24749 | \n",
" 2018-05-20 18:30:00 | \n",
" La Liga | \n",
" Atl\\u00e9tico Madrid - Eibar | \n",
" Eibar | \n",
" Atl\\u00e9tico Madrid | \n",
" 2 | \n",
" 2 | \n",
" Shot | \n",
" 16 | \n",
" 7 | \n",
" 38 | \n",
"
\n",
" \n",
" 24750 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Duel | \n",
" 182 | \n",
" 200 | \n",
" 38 | \n",
"
\n",
" \n",
" 24751 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Foul | \n",
" 13 | \n",
" 13 | \n",
" 38 | \n",
"
\n",
" \n",
" 24752 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Free Kick | \n",
" 38 | \n",
" 37 | \n",
" 38 | \n",
"
\n",
" \n",
" 24753 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Goalkeeper leaving line | \n",
" 2 | \n",
" 1 | \n",
" 38 | \n",
"
\n",
" \n",
" 24754 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Offside | \n",
" 3 | \n",
" 3 | \n",
" 38 | \n",
"
\n",
" \n",
" 24755 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Others on the ball | \n",
" 95 | \n",
" 81 | \n",
" 38 | \n",
"
\n",
" \n",
" 24756 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Pass | \n",
" 592 | \n",
" 360 | \n",
" 38 | \n",
"
\n",
" \n",
" 24757 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Save attempt | \n",
" 2 | \n",
" 4 | \n",
" 38 | \n",
"
\n",
" \n",
" 24758 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Barcelona | \n",
" Real Sociedad | \n",
" 1 | \n",
" 0 | \n",
" Shot | \n",
" 10 | \n",
" 12 | \n",
" 38 | \n",
"
\n",
" \n",
" 24759 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Duel | \n",
" 200 | \n",
" 182 | \n",
" 38 | \n",
"
\n",
" \n",
" 24760 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Foul | \n",
" 13 | \n",
" 13 | \n",
" 38 | \n",
"
\n",
" \n",
" 24761 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Free Kick | \n",
" 37 | \n",
" 38 | \n",
" 38 | \n",
"
\n",
" \n",
" 24762 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Goalkeeper leaving line | \n",
" 1 | \n",
" 2 | \n",
" 38 | \n",
"
\n",
" \n",
" 24763 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Offside | \n",
" 3 | \n",
" 3 | \n",
" 38 | \n",
"
\n",
" \n",
" 24764 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Others on the ball | \n",
" 81 | \n",
" 95 | \n",
" 38 | \n",
"
\n",
" \n",
" 24765 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Pass | \n",
" 360 | \n",
" 592 | \n",
" 38 | \n",
"
\n",
" \n",
" 24766 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Save attempt | \n",
" 4 | \n",
" 2 | \n",
" 38 | \n",
"
\n",
" \n",
" 24767 | \n",
" 2018-05-20 20:45:00 | \n",
" La Liga | \n",
" Barcelona - Real Sociedad | \n",
" Real Sociedad | \n",
" Barcelona | \n",
" 1 | \n",
" 0 | \n",
" Shot | \n",
" 12 | \n",
" 10 | \n",
" 38 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Date League_Name Fixture \\\n",
"24718 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24719 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24720 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24721 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24722 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24723 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24724 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24725 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24726 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24727 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24728 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24729 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24730 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24731 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24732 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24733 2018-05-20 16:15:00 La Liga Athletic Club - Espanyol \n",
"24734 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24735 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24736 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24737 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24738 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24739 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24740 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24741 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24742 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24743 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24744 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24745 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24746 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24747 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24748 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24749 2018-05-20 18:30:00 La Liga Atl\\u00e9tico Madrid - Eibar \n",
"24750 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24751 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24752 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24753 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24754 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24755 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24756 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24757 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24758 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24759 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24760 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24761 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24762 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24763 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24764 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24765 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24766 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"24767 2018-05-20 20:45:00 La Liga Barcelona - Real Sociedad \n",
"\n",
" Team Opponent Goals_Home Goals_Away \\\n",
"24718 Athletic Club Espanyol 0 1 \n",
"24719 Athletic Club Espanyol 0 1 \n",
"24720 Athletic Club Espanyol 0 1 \n",
"24721 Athletic Club Espanyol 0 1 \n",
"24722 Athletic Club Espanyol 0 1 \n",
"24723 Athletic Club Espanyol 0 1 \n",
"24724 Athletic Club Espanyol 0 1 \n",
"24725 Espanyol Athletic Club 0 1 \n",
"24726 Espanyol Athletic Club 0 1 \n",
"24727 Espanyol Athletic Club 0 1 \n",
"24728 Espanyol Athletic Club 0 1 \n",
"24729 Espanyol Athletic Club 0 1 \n",
"24730 Espanyol Athletic Club 0 1 \n",
"24731 Espanyol Athletic Club 0 1 \n",
"24732 Espanyol Athletic Club 0 1 \n",
"24733 Espanyol Athletic Club 0 1 \n",
"24734 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24735 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24736 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24737 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24738 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24739 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24740 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24741 Atl\\u00e9tico Madrid Eibar 2 2 \n",
"24742 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24743 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24744 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24745 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24746 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24747 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24748 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24749 Eibar Atl\\u00e9tico Madrid 2 2 \n",
"24750 Barcelona Real Sociedad 1 0 \n",
"24751 Barcelona Real Sociedad 1 0 \n",
"24752 Barcelona Real Sociedad 1 0 \n",
"24753 Barcelona Real Sociedad 1 0 \n",
"24754 Barcelona Real Sociedad 1 0 \n",
"24755 Barcelona Real Sociedad 1 0 \n",
"24756 Barcelona Real Sociedad 1 0 \n",
"24757 Barcelona Real Sociedad 1 0 \n",
"24758 Barcelona Real Sociedad 1 0 \n",
"24759 Real Sociedad Barcelona 1 0 \n",
"24760 Real Sociedad Barcelona 1 0 \n",
"24761 Real Sociedad Barcelona 1 0 \n",
"24762 Real Sociedad Barcelona 1 0 \n",
"24763 Real Sociedad Barcelona 1 0 \n",
"24764 Real Sociedad Barcelona 1 0 \n",
"24765 Real Sociedad Barcelona 1 0 \n",
"24766 Real Sociedad Barcelona 1 0 \n",
"24767 Real Sociedad Barcelona 1 0 \n",
"\n",
" Event Team_Value Opponent_Value Gameweek \n",
"24718 Free Kick 36 39 38 \n",
"24719 Goalkeeper leaving line 3 2 38 \n",
"24720 Offside 2 5 38 \n",
"24721 Others on the ball 67 78 38 \n",
"24722 Pass 512 407 38 \n",
"24723 Save attempt 4 3 38 \n",
"24724 Shot 9 12 38 \n",
"24725 Duel 147 154 38 \n",
"24726 Foul 11 4 38 \n",
"24727 Free Kick 39 36 38 \n",
"24728 Goalkeeper leaving line 2 3 38 \n",
"24729 Offside 5 2 38 \n",
"24730 Others on the ball 78 67 38 \n",
"24731 Pass 407 512 38 \n",
"24732 Save attempt 3 4 38 \n",
"24733 Shot 12 9 38 \n",
"24734 Duel 191 181 38 \n",
"24735 Foul 15 13 38 \n",
"24736 Free Kick 56 34 38 \n",
"24737 Offside 6 0 38 \n",
"24738 Others on the ball 56 64 38 \n",
"24739 Pass 428 406 38 \n",
"24740 Save attempt 6 4 38 \n",
"24741 Shot 7 16 38 \n",
"24742 Duel 181 191 38 \n",
"24743 Foul 13 15 38 \n",
"24744 Free Kick 34 56 38 \n",
"24745 Goalkeeper leaving line 2 0 38 \n",
"24746 Others on the ball 64 56 38 \n",
"24747 Pass 406 428 38 \n",
"24748 Save attempt 4 6 38 \n",
"24749 Shot 16 7 38 \n",
"24750 Duel 182 200 38 \n",
"24751 Foul 13 13 38 \n",
"24752 Free Kick 38 37 38 \n",
"24753 Goalkeeper leaving line 2 1 38 \n",
"24754 Offside 3 3 38 \n",
"24755 Others on the ball 95 81 38 \n",
"24756 Pass 592 360 38 \n",
"24757 Save attempt 2 4 38 \n",
"24758 Shot 10 12 38 \n",
"24759 Duel 200 182 38 \n",
"24760 Foul 13 13 38 \n",
"24761 Free Kick 37 38 38 \n",
"24762 Goalkeeper leaving line 1 2 38 \n",
"24763 Offside 3 3 38 \n",
"24764 Others on the ball 81 95 38 \n",
"24765 Pass 360 592 38 \n",
"24766 Save attempt 4 2 38 \n",
"24767 Shot 12 10 38 "
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Display DataFrame\n",
"df_wyscout_fixture_grouped.tail(50)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"df_wyscout_fixture_grouped.to_csv(data_dir_wyscout + '/engineered/combined/wyscout_aggregated_fixtures_big5_1718.csv', index=None, header=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4.8.2. Team Level"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" League_Name | \n",
" Team | \n",
" Event | \n",
" Team_Value | \n",
" Opponent_Value | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Bundesliga | \n",
" Augsburg | \n",
" Duel | \n",
" 7240 | \n",
" 7292 | \n",
"
\n",
" \n",
" 1 | \n",
" Bundesliga | \n",
" Augsburg | \n",
" Foul | \n",
" 497 | \n",
" 433 | \n",
"
\n",
" \n",
" 2 | \n",
" Bundesliga | \n",
" Augsburg | \n",
" Free Kick | \n",
" 1660 | \n",
" 1686 | \n",
"
\n",
" \n",
" 3 | \n",
" Bundesliga | \n",
" Augsburg | \n",
" Goalkeeper leaving line | \n",
" 41 | \n",
" 42 | \n",
"
\n",
" \n",
" 4 | \n",
" Bundesliga | \n",
" Augsburg | \n",
" Offside | \n",
" 73 | \n",
" 28 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" League_Name Team Event Team_Value Opponent_Value\n",
"0 Bundesliga Augsburg Duel 7240 7292\n",
"1 Bundesliga Augsburg Foul 497 433\n",
"2 Bundesliga Augsburg Free Kick 1660 1686\n",
"3 Bundesliga Augsburg Goalkeeper leaving line 41 42\n",
"4 Bundesliga Augsburg Offside 73 28"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Group DataFrame by Team\n",
"\n",
"##\n",
"df_wyscout_team_grouped = (df_wyscout_fixture_grouped\n",
" .groupby(['League_Name', 'Team', 'Event'])\n",
" .agg({'Team_Value': ['sum'],\n",
" 'Opponent_Value': ['sum']\n",
" }\n",
" )\n",
" )\n",
"\n",
"##\n",
"df_wyscout_team_grouped.columns = df_wyscout_team_grouped.columns.droplevel(level=0)\n",
"\n",
"##\n",
"df_wyscout_team_grouped = df_wyscout_team_grouped.reset_index()\n",
"\n",
"## Rename columns\n",
"df_wyscout_team_grouped.columns = ['League_Name', 'Team', 'Event', 'Team_Value', 'Opponent_Value']\n",
"\n",
"## Display columns\n",
"df_wyscout_team_grouped.head()"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"df_wyscout_team_grouped.to_csv(data_dir_wyscout + '/engineered/combined/wyscout_aggregated_team_big5_1718.csv', index=None, header=True)"
]
}
],
"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()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}