<jupyter_start><jupyter_text>[RQ5] Does being a tall player mean winning more air duels? Soccer is a physical game, and it happens often in a match that players are involved in air duels (i.e. when two players are contending for the ball while it is not on the ground). Make a plot that shows the dependency between height of the player and the ratio of air duels won with air duels attempted. The visualization should be a scatterplot, where each point (x,y) represent a player whose height is equal to x, and that has a ratio of winning air duels equal to y. Furthermore, color any point according an arbitrary selection of categories of height (e.g. yellow: 160-165cm, orange: 165-170cm, etc.)Remember that the "Air Duel" is a subevent of the event "Duel" and that an air duel is said to be won if it has the tag "1801". Same as in RQ4, choose a threshold of minimum air duels attempted, in order filter your data, get reliable results, and justify your choice.<jupyter_code>import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
dataset=pd.read_json(r"events/events_England.json")
#selecting only air duels
eventofinterest=dataset[dataset["subEventName"]=='Air duel']
eventofinterest.reset_index(inplace=True,drop=True)
eventofinterest.head()
# data set says that if tags 1801 then it is a successive event.
#Filtering only the data that they are equal to 1801
eventofsucessive=eventofinterest[[eventofinterest["tags"][i][1]['id'] == 1801 for i in range(eventofinterest["tags"].shape[0])]]
eventofsucessive.drop(["positions","matchId","teamId","matchPeriod","id"],axis=1,inplace=True)
eventofsucessive.head()
#groupby the players and count them
succesivecount=eventofsucessive.groupby("playerId").count()
succesivecount.drop(["subEventName","tags","eventName","eventSec","subEventId"],axis=1,inplace=True)
succesivecount.reset_index(inplace=True)
succesivecount.head()

teamdata=pd.read_json("players.json")
teamdata=teamdata[["firstName","middleName","lastName","height","wyId"]]
teamdata.head()

#to finding player name merge them on player Id
lastdata=succesivecount.merge(teamdata,left_on="playerId",right_on="wyId")
lastdata.drop("wyId",axis=1,inplace=True)
lastdata.head()
#total number of passes that each player done 
eventoftotal=eventofinterest.groupby("playerId").count()
eventoftotal.reset_index(inplace=True)
eventoftotal=eventoftotal[["playerId","eventId"]]
eventoftotal.rename(columns={"eventId":"totalduel"},inplace=True)
eventoftotal.head()
#merging both succesive duels and totalduels on player id
lastdata=lastdata.merge(eventoftotal,left_on="playerId",right_on="playerId")
lastdata.rename(columns={"eventId":"succesiveduel"},inplace=True)
lastdata.head()
#calculating ratio between successive and all air duel
lastdata["ratio"]=lastdata["succesiveduel"]/lastdata["totalduel"]
#if total duel less then 50 , find their mean and remove their standart deviation to filter ratio
lastdata=lastdata.sort_values(by="totalduel").reset_index(drop=True)
lastdata=lastdata[lastdata["totalduel"]>=
         lastdata[lastdata["totalduel"]>=50]["totalduel"].mean()-(lastdata[lastdata["totalduel"]>=50]["totalduel"].std())/2]
lastdata=lastdata.sort_values(by="ratio",ascending=False).reset_index(drop=True)
lastdata.head()
# plt.figure(figsize=(10,7))
colormap=np.array(["r","g","b"])
categories=np.array(list(range(lastdata.shape[0])))
plt.scatter(lastdata[lastdata["height"]<=170].height,
            lastdata[lastdata["height"]<=170].ratio,color="darkorange",label="o<=170")
plt.scatter(lastdata[(lastdata["height"]<=180)&(lastdata["height"]>170)].height,
            lastdata[(lastdata["height"]<=180)&(lastdata["height"]>170)].ratio,color="royalblue",
            label="170<o<=180")
plt.scatter(lastdata[lastdata["height"]>180].height,
            lastdata[lastdata["height"]>180].ratio,color="yellow",label="o>180")
plt.legend()
plt.xlabel("Height")
plt.ylabel("Succesratio")
plt.title("Height-Succes Ratio")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1392947103274559, 'fraction_numerical': 0.02065491183879093, 'mean_word_length': 7.8244444444444445, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 13, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '258882', 'license': 'MIT', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1241, 'n_words': 316, 'path': 'codesforquestions/Question5.ipynb', 'repo_name': 'vedatk67/ADM-HW2', 'size': '3970'}