{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#edit only this tab\n", "#give the folder path of the match\n", "path = \"/home/kirugulige/Documents/Football-Analytics/open-data-master/data/events/\"\n", "home_team = 'Espanyol'\n", "away_team = 'Barcelona'" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "done\n" ] } ], "source": [ "import json\n", "import os\n", "import codecs\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from matplotlib.patches import Arc, Rectangle, ConnectionPatch\n", "from matplotlib.offsetbox import OffsetImage\n", "import StatsbombPitch as sb\n", "from functools import reduce\n", "from pandas.io.json import json_normalize\n", "\n", "Xg_req = pd.DataFrame(data=None)\n", "\n", "filename = '69275.json' # remove the comment line to work for this match\n", "with codecs.open(\"%s\" % path + filename,encoding='utf-8') as data_file: \n", " data = json.load(data_file)\n", " df = pd.DataFrame(data=None)\n", " \n", " df = json_normalize(data, sep = \"_\")\n", " \n", " #df = df[(df['type_name'] == \"Shot\")]\n", " #df = df.loc[:,['location','shot_body_part_id','shot_end_location','shot_one_on_one','shot_technique_id','shot_type_id','under_pressure','shot_outcome_id']]\n", " #print(df.shape)\n", "Xg_req = Xg_req.append(df,ignore_index=True,sort=False)\n", " #df.drop(df.index, inplace=True)\n", " \n", "print(\"done\")\n", "df = Xg_req" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "#type_id=30 is pass event AND type_id=19 is substitution event\n", "\n", "pass_m = df.query('type_id == 30')\n", "substitution = df.query('type_id == 19')\n", "#pass_m = df.query('type_name == pass')\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Javier Alejandro Mascherano' 'Seydou Kéita' 'Bojan Krkíc Pérez']\n", "['Jesús Alberto Dátolo' 'Jordi Amat Maas' 'David García De La Cruz']\n" ] } ], "source": [ "#this cell is WIP\n", "substitution_home = set()\n", "substitution_home = substitution[substitution.team_name == home_team]\n", "substitution_home = substitution_home['substitution_replacement_name'].unique()\n", "substitution_away = set()\n", "substitution_away = substitution[substitution.team_name == away_team]\n", "substitution_away = substitution_away['substitution_replacement_name'].unique()\n", "print(substitution_away)\n", "print(substitution_home)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "# to get \n", "\n", "home_player = pass_m[(pass_m.team_name == home_team)] \n", "home_team_list = set()\n", "home_team_list = home_player['player_name'].unique()\n", "#print(substitution_belgium)\n", "#belgium_list = [player for player in belgium_list if player not in substitution_belgium]\n", "#belgium_list.remove([x for x in substitution_belgium])#belgium_list - substitution_belgium\n", "home_player =pass_m['player_name'].isin(home_team_list)\n", "pass_home = pass_m[home_player] #contains 11 players of home team\n", "\n", "away_player = pass_m[(pass_m.team_name == away_team)] \n", "away_list = away_player['player_name'].unique()\n", "#away_list = away_list - substitution_brazil\n", "away_player = pass_m['player_name'].isin(away_list)\n", "pass_away = pass_m[away_player]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | id | \n", "index | \n", "period | \n", "timestamp | \n", "minute | \n", "second | \n", "possession | \n", "duration | \n", "type_id | \n", "type_name | \n", "... | \n", "pass_cut_back | \n", "substitution_outcome_id | \n", "substitution_outcome_name | \n", "substitution_replacement_id | \n", "substitution_replacement_name | \n", "injury_stoppage_in_chain | \n", "foul_committed_offensive | \n", "pass_deflected | \n", "block_deflection | \n", "goalkeeper_punched_out | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | \n", "d6406089-778b-49e0-a70a-ade4788cf911 | \n", "5 | \n", "1 | \n", "00:00:00.738 | \n", "0 | \n", "0 | \n", "2 | \n", "0.606100 | \n", "30 | \n", "Pass | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
8 | \n", "73d8e43f-8e84-4b5d-88cc-9423278134d5 | \n", "9 | \n", "1 | \n", "00:00:02.511 | \n", "0 | \n", "2 | \n", "2 | \n", "1.776163 | \n", "30 | \n", "Pass | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
16 | \n", "8e47d35d-ab38-4419-a991-efe7105dec56 | \n", "17 | \n", "1 | \n", "00:00:09.581 | \n", "0 | \n", "9 | \n", "2 | \n", "1.242900 | \n", "30 | \n", "Pass | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
20 | \n", "a449bfa2-7bd9-4f94-8e13-595620c9bcee | \n", "21 | \n", "1 | \n", "00:00:18.784 | \n", "0 | \n", "18 | \n", "3 | \n", "1.298500 | \n", "30 | \n", "Pass | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
24 | \n", "77f45a53-2eab-4ee5-bfbd-ad39d20a36cb | \n", "25 | \n", "1 | \n", "00:00:20.122 | \n", "0 | \n", "20 | \n", "3 | \n", "0.950262 | \n", "30 | \n", "Pass | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
5 rows × 122 columns
\n", "