{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
eventIdsubEventNametagsplayerIdpositionsmatchIdeventNameteamIdmatchPeriodeventSecsubEventIdidstatusroundIdgameweekseasonIddateutcwinnervenuewyId_xlabeldaterefereesdurationcompetitionIdleague_namewyId_ycountryweightfirstNamemiddleNamelastNamebirthDateheightwyId_x.1footshortNamepassportArea.namerole.namebirthArea.namefullNameteamNamewyId_y.1fixturescore_home_awayteam_hometeam_awaygoals_homegoals_awaydate_isolatedtime_isolateddate_time_isolateddate_time_timestampdate_datetime_timefull_fixture_dateseasonteamIdNextteamNameNextfullNameNextplayer2playerisPossessionRetained
08Simple pass[{'id': 1801}]134351[{'y': 50, 'x': 50}, {'y': 57, 'x': 40}]2499930Pass16591H1.91444985.0218431699Played4405654221811502018-01-01 12:30:000The American Express Community Stadium2499930Brighton & Hove Albion - AFC Bournemouth, 2 - 2January 1, 2018 at 1:30:00 PM GMT+1[{'refereeId': 384965, 'role': 'referee'}, {'r...Regular364Premier League364England78BenikNaNAfobe1993-02-12183134351rightB. AfobeCongo DRForwardEnglandBenik AfobeAFC Bournemouth1659Brighton & Hove Albion - AFC Bournemouth2 - 2Brighton & Hove AlbionAFC Bournemouth22January 1, 20181:30:00 PM GMT+1January 1, 2018 1:30:00 PM2018-01-01 13:30:0001-01-201813:30:0001-01-2018 Brighton & Hove Albion 2 v 2 AFC ...17/181659.0AFC BournemouthLewis CookBenik Afobe - Lewis CookTrue
18Simple pass[{'id': 1801}]302518[{'y': 57, 'x': 40}, {'y': 12, 'x': 33}]2499930Pass16591H2.78423085.0218431700Played4405654221811502018-01-01 12:30:000The American Express Community Stadium2499930Brighton & Hove Albion - AFC Bournemouth, 2 - 2January 1, 2018 at 1:30:00 PM GMT+1[{'refereeId': 384965, 'role': 'referee'}, {'r...Regular364Premier League364England71LewisNaNCook1997-02-03175302518rightL. CookEnglandMidfielderEnglandLewis CookAFC Bournemouth1659Brighton & Hove Albion - AFC Bournemouth2 - 2Brighton & Hove AlbionAFC Bournemouth22January 1, 20181:30:00 PM GMT+1January 1, 2018 1:30:00 PM2018-01-01 13:30:0001-01-201813:30:0001-01-2018 Brighton & Hove Albion 2 v 2 AFC ...17/181659.0AFC BournemouthCharlie DanielsLewis Cook - Charlie DanielsTrue
28Simple pass[{'id': 1801}]9285[{'y': 12, 'x': 33}, {'y': 4, 'x': 38}]2499930Pass16591H5.04010685.0218431701Played4405654221811502018-01-01 12:30:000The American Express Community Stadium2499930Brighton & Hove Albion - AFC Bournemouth, 2 - 2January 1, 2018 at 1:30:00 PM GMT+1[{'refereeId': 384965, 'role': 'referee'}, {'r...Regular364Premier League364England75CharlieNaNDaniels1986-09-071789285leftC. DanielsEnglandDefenderEnglandCharlie DanielsAFC Bournemouth1659Brighton & Hove Albion - AFC Bournemouth2 - 2Brighton & Hove AlbionAFC Bournemouth22January 1, 20181:30:00 PM GMT+1January 1, 2018 1:30:00 PM2018-01-01 13:30:0001-01-201813:30:0001-01-2018 Brighton & Hove Albion 2 v 2 AFC ...17/181659.0AFC BournemouthMarc PughCharlie Daniels - Marc PughTrue
38Simple pass[{'id': 1801}]9293[{'y': 4, 'x': 38}, {'y': 26, 'x': 41}]2499930Pass16591H6.54486985.0218431702Played4405654221811502018-01-01 12:30:000The American Express Community Stadium2499930Brighton & Hove Albion - AFC Bournemouth, 2 - 2January 1, 2018 at 1:30:00 PM GMT+1[{'refereeId': 384965, 'role': 'referee'}, {'r...Regular364Premier League364England72MarcNaNPugh1987-04-021809293rightM. PughEnglandMidfielderEnglandMarc PughAFC Bournemouth1659Brighton & Hove Albion - AFC Bournemouth2 - 2Brighton & Hove AlbionAFC Bournemouth22January 1, 20181:30:00 PM GMT+1January 1, 2018 1:30:00 PM2018-01-01 13:30:0001-01-201813:30:0001-01-2018 Brighton & Hove Albion 2 v 2 AFC ...17/181659.0AFC BournemouthHarry ArterMarc Pugh - Harry ArterTrue
48Simple pass[{'id': 1801}]9283[{'y': 26, 'x': 41}, {'y': 10, 'x': 53}]2499930Pass16591H8.24574585.0218431703Played4405654221811502018-01-01 12:30:000The American Express Community Stadium2499930Brighton & Hove Albion - AFC Bournemouth, 2 - 2January 1, 2018 at 1:30:00 PM GMT+1[{'refereeId': 384965, 'role': 'referee'}, {'r...Regular364Premier League364England70HarryNaNArter1989-12-281789283rightH. ArterIreland RepublicMidfielderEnglandHarry ArterAFC Bournemouth1659Brighton & Hove Albion - AFC Bournemouth2 - 2Brighton & Hove AlbionAFC Bournemouth22January 1, 20181:30:00 PM GMT+1January 1, 2018 1:30:00 PM2018-01-01 13:30:0001-01-201813:30:0001-01-2018 Brighton & Hove Albion 2 v 2 AFC ...17/181659.0AFC BournemouthMarc PughHarry Arter - Marc PughTrue
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateLeague_NameFixtureTeamOpponentGoals_HomeGoals_AwayEventSubEventTeam_Value
02017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32DuelAir duel67
12017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32DuelGround attacking duel75
22017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32DuelGround defending duel49
32017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32DuelGround loose ball duel29
42017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32FoulFoul12
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateLeague_NameFixtureTeam_xOpponent_xGoals_Home_xGoals_Away_xEventTeam_Value_xTeam_yOpponent_yGoals_Home_yGoals_Away_yTeam_Value_y
02017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Duel220ToulouseMonaco3.02.0205.0
12017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Foul12ToulouseMonaco3.02.023.0
22017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Free Kick58ToulouseMonaco3.02.047.0
32017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Goalkeeper leaving line2NaNNaNNaNNaNNaN
42017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Offside5ToulouseMonaco3.02.01.0
.............................................
247632018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Offside3BarcelonaReal Sociedad1.00.03.0
247642018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Others on the ball81BarcelonaReal Sociedad1.00.095.0
247652018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Pass360BarcelonaReal Sociedad1.00.0592.0
247662018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Save attempt4BarcelonaReal Sociedad1.00.02.0
247672018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Shot12BarcelonaReal Sociedad1.00.010.0
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateLeague_NameFixtureTeamOpponentGoals_HomeGoals_AwayEventTeam_ValueOpponent_Value
02017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Duel220205
12017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Foul1223
22017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Free Kick5847
32017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Goalkeeper leaving line20
42017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Offside51
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TeamDateGameweek
0AFC Bournemouth2017-08-12 16:00:001
1AFC Bournemouth2017-08-19 16:00:002
2AFC Bournemouth2017-08-26 13:30:003
3AFC Bournemouth2017-09-09 16:00:004
4AFC Bournemouth2017-09-15 21:00:005
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateLeague_NameFixtureTeamOpponentGoals_HomeGoals_AwayEventTeam_ValueOpponent_ValueGameweek
02017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Duel2202051
12017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Foul12231
22017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Free Kick58471
32017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Goalkeeper leaving line201
42017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Offside511
52017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Others on the ball46491
62017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Pass4671701
72017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Save attempt471
82017-08-04 20:45:00Ligue 1Monaco - ToulouseMonacoToulouse32Shot1241
92017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Duel2052201
102017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Foul23121
112017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Free Kick47581
122017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Offside151
132017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Others on the ball49461
142017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Pass1704671
152017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Save attempt741
162017-08-04 20:45:00Ligue 1Monaco - ToulouseToulouseMonaco32Shot4121
172017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Duel2051921
182017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Foul1291
192017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Free Kick33411
202017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Goalkeeper leaving line131
212017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Others on the ball82551
222017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Pass3287241
232017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Save attempt511
242017-08-05 17:15:00Ligue 1PSG - Amiens SCAmiens SCPSG20Shot6151
252017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Duel1922051
262017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Foul9121
272017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Free Kick41331
282017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Goalkeeper leaving line311
292017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Offside301
302017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Others on the ball55821
312017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Pass7243281
322017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Save attempt151
332017-08-05 17:15:00Ligue 1PSG - Amiens SCPSGAmiens SC20Shot1561
342017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Duel1601681
352017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Foul1271
362017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Free Kick34511
372017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Goalkeeper leaving line411
382017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Offside131
392017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Others on the ball46441
402017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Pass3965281
412017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Save attempt451
422017-08-05 20:00:00Ligue 1Metz - GuingampGuingampMetz13Shot861
432017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Duel1681601
442017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Foul7121
452017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Free Kick51341
462017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Goalkeeper leaving line141
472017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Offside311
482017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Others on the ball44461
492017-08-05 20:00:00Ligue 1Metz - GuingampMetzGuingamp13Pass5283961
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateLeague_NameFixtureTeamOpponentGoals_HomeGoals_AwayEventTeam_ValueOpponent_ValueGameweek
247182018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Free Kick363938
247192018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Goalkeeper leaving line3238
247202018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Offside2538
247212018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Others on the ball677838
247222018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Pass51240738
247232018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Save attempt4338
247242018-05-20 16:15:00La LigaAthletic Club - EspanyolAthletic ClubEspanyol01Shot91238
247252018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Duel14715438
247262018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Foul11438
247272018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Free Kick393638
247282018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Goalkeeper leaving line2338
247292018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Offside5238
247302018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Others on the ball786738
247312018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Pass40751238
247322018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Save attempt3438
247332018-05-20 16:15:00La LigaAthletic Club - EspanyolEspanyolAthletic Club01Shot12938
247342018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Duel19118138
247352018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Foul151338
247362018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Free Kick563438
247372018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Offside6038
247382018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Others on the ball566438
247392018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Pass42840638
247402018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Save attempt6438
247412018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarAtl\\u00e9tico MadridEibar22Shot71638
247422018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Duel18119138
247432018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Foul131538
247442018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Free Kick345638
247452018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Goalkeeper leaving line2038
247462018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Others on the ball645638
247472018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Pass40642838
247482018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Save attempt4638
247492018-05-20 18:30:00La LigaAtl\\u00e9tico Madrid - EibarEibarAtl\\u00e9tico Madrid22Shot16738
247502018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Duel18220038
247512018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Foul131338
247522018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Free Kick383738
247532018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Goalkeeper leaving line2138
247542018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Offside3338
247552018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Others on the ball958138
247562018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Pass59236038
247572018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Save attempt2438
247582018-05-20 20:45:00La LigaBarcelona - Real SociedadBarcelonaReal Sociedad10Shot101238
247592018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Duel20018238
247602018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Foul131338
247612018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Free Kick373838
247622018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Goalkeeper leaving line1238
247632018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Offside3338
247642018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Others on the ball819538
247652018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Pass36059238
247662018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Save attempt4238
247672018-05-20 20:45:00La LigaBarcelona - Real SociedadReal SociedadBarcelona10Shot121038
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
League_NameTeamEventTeam_ValueOpponent_Value
0BundesligaAugsburgDuel72407292
1BundesligaAugsburgFoul497433
2BundesligaAugsburgFree Kick16601686
3BundesligaAugsburgGoalkeeper leaving line4142
4BundesligaAugsburgOffside7328
\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 }