<jupyter_start><jupyter_text>CRQ-1 [CRQ1] What are the time slots of the match with more goals? Let's analyse and visualise the goals distribution into 9-minutes sets for all the matches. I.e., let's transform the minute of a goal from a continuous variable in a discrete variable (e.g. A goal scored in 5th minute, will end up in the interval [0-9)). Remind that every match goes usually from minute 0, to minute 90, but in football it is always added an arbitary amount of extra-time to every half of the match, thus consider also the intervals "45+" and "90+".    Make a barplot with the absolute frequency of goals in all the time slots.    Find the top 10 teams that score the most in the interval "81-90".    Show if there are players that were able to score at least one goal in 8 different intervals.<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

matches_england=pd.read_json(r"matches\matches_England.json")
matches_england.head()
events_england=pd.read_json(r"events\events_England.json")
events_england.head()
eventofshoot=events_england[events_england["subEventName"]=="Shot"]["tags"].reset_index(drop=False)
eventofshoot.rename(columns={"index":"exindex"},inplace=True)
eventofshoot.head()
#if eventof shoot tags == 101 select them and filter the data by if they are true 
goals=[]
counter=0
for i in range(eventofshoot.shape[0]):
    goals.append(eventofshoot["tags"][i][0]["id"]==101)
        
goals=eventofshoot[goals]
goals.drop(["tags"],axis=1,inplace=True)
goals.head()
#selecting the only goal shoots from events of england
events_england=events_england.loc[goals["exindex"]]
events_england.head()
#converting seconds to minute 
events_england["eventSec"]= events_england["eventSec"]/60
events_england.head()
#converting columns in to integer and assign them into specified intervals
events_england["eventSec"]=events_england["eventSec"].astype(int)
events_england['interval'] = np.digitize(events_england['eventSec'], [i for i in range(9,55,9)], right=True) + 1
# for the second half add 6 to interval
events_england.loc[events_england[events_england["matchPeriod"]=="2H"].index,"interval"] += 6
# grouping by intervals
data=events_england.groupby("interval").count()
data<jupyter_output><empty_output><jupyter_text>Goal frequencies Bar plot<jupyter_code>plt.figure(figsize=(10,6))
plt.bar(data.index,data.iloc[:,1],tick_label=["0-9","9-18","18-27","27-36","36-45","45+","45-54","54-63","63-72","72-81","81-90","90+"])
plt.xlabel("Time Intervals")
plt.ylabel("Goal Frequencies")

plt.title("Goal Frequencies in Time Interval",fontname='Arial',fontsize=20)
teamsdata=pd.read_json("teams.json")
teamsdata=teamsdata[["name","wyId"]]
#finding the topten score team 
toptenteam=events_england[events_england["interval"]==11].groupby("teamId").count().sort_values(
    "eventId",ascending=False).iloc[:10].reset_index().merge(teamsdata,left_on="teamId",right_on="wyId")[["eventId","name"]]<jupyter_output><empty_output><jupyter_text>Top ten score n interval 81-90<jupyter_code>toptenteam.rename(columns={"eventId":"81-90 goals"},inplace=True)
toptenteam

playerid=[]
for i in pd.unique(events_england["playerId"]):
    if len(pd.unique(events_england.groupby("playerId").get_group(i)["interval"])) >= 8 :
        playerid.append(i)
  

dataset=pd.read_json("players.json")
dataset=dataset[dataset["wyId"].isin(playerid)]<jupyter_output><empty_output><jupyter_text>People who score at least 8 times intervals<jupyter_code>dataset[["firstName","lastName"]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14132278123233466, 'fraction_numerical': 0.0285472018089316, 'mean_word_length': 7.466507177033493, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '418041', 'license': 'MIT', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1181, 'n_words': 285, 'path': 'codesforquestions/CRQ1.ipynb', 'repo_name': 'vedatk67/ADM-HW2', 'size': '3538'}