{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#edit only this tab\n", "#give the folder path of the match\n", "path = \"\"\"C:\\\\Users\\\\koushik.r\\\\Documents\\\\open-data-master\\\\data\\\\events\\\\\"\"\"\n", "home_team = 'Espanyol'\n", "away_team = 'Barcelona'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "done\n" ] } ], "source": [ "import json\n", "import os\n", "import codecs\n", "from pandas.io.json import json_normalize\n", "import numpy as np\n", "#import seaborn as sns\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 squarify\n", "from functools import reduce\n", "\n", "Xg_req = pd.DataFrame(data=None)\n", "for filename in (os.listdir(path)):\n", " #print(filename)\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": 3, "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": 4, "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": 5, "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", " | 50_50_outcome_id | \n", "50_50_outcome_name | \n", "bad_behaviour_card_id | \n", "bad_behaviour_card_name | \n", "ball_receipt_outcome_id | \n", "ball_receipt_outcome_name | \n", "ball_recovery_recovery_failure | \n", "block_deflection | \n", "block_offensive | \n", "carry_end_location | \n", "... | \n", "substitution_replacement_id | \n", "substitution_replacement_name | \n", "tactics_formation | \n", "tactics_lineup | \n", "team_id | \n", "team_name | \n", "timestamp | \n", "type_id | \n", "type_name | \n", "under_pressure | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:00.738 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
8 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:02.511 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
16 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:09.581 | \n", "30 | \n", "Pass | \n", "True | \n", "
20 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:18.784 | \n", "30 | \n", "Pass | \n", "NaN | \n", "
24 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "214 | \n", "Espanyol | \n", "00:00:20.122 | \n", "30 | \n", "Pass | \n", "True | \n", "
5 rows × 122 columns
\n", "