<jupyter_start><jupyter_text>Player Analysis<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Data Cleaning and Exploration<jupyter_code>df1 = pd.read_csv("matches.csv")
df2 = pd.read_csv("deliveries.csv")

df1.rename(columns={"id" : 'match_id'}, inplace=True)

matches= pd.merge(df1, df2, on='match_id', how='outer')
matches.columns
matches = matches[['match_id', 'season','team1', 'team2', 'toss_winner','toss_decision','winner',
       'inning', 'batting_team', 'bowling_team', 'over', 'ball',
       'batsman','non_striker', 'bowler','wide_runs','bye_runs', 'legbye_runs','noball_runs',
       'batsman_runs', 'extra_runs', 'total_runs', 'player_dismissed',
       'dismissal_kind']]

matches.shape
matches.head()<jupyter_output><empty_output><jupyter_text>Taking in Consideration only MI VS RR matches<jupyter_code>MI_RR =matches[np.logical_or(np.logical_and(matches['team1']=='Mumbai Indians',matches['team2']=='Rajasthan Royals'),
                            np.logical_and(matches['team2']=='Mumbai Indians',matches['team1']=='Rajasthan Royals'))]
MI_RR.head()
MI_RR.match_id.nunique()
MI_RR.season.unique()<jupyter_output><empty_output><jupyter_text>BIS Calculation  Q de Kock - Total runs scored by the batsman<jupyter_code>qdk = MI_RR[(MI_RR["batting_team"] == "Mumbai Indians")&(MI_RR["batsman"]=="Q de Kock")]
qdk.iloc[:,4:].head()
qdk_runs= qdk[qdk["wide_runs"]==0]
batsman_runs11 = qdk_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs11<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>qdk_runs.batsman_runs.unique()
qdk_boundaries = qdk_runs[(qdk_runs["batsman_runs"]==4)|(qdk_runs["batsman_runs"]==6)]

boundary_runs11 = pd.DataFrame(qdk_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs11.columns = ["boundary runs"]

boundary_runs11<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>qdk_running = qdk_runs[(qdk_runs["batsman_runs"]==1)|(qdk_runs["batsman_runs"]==2)|(qdk_runs["batsman_runs"]==3)]

batsman_running11 = pd.DataFrame(qdk_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running11.columns = ["running runs"]

batsman_running11
final11 = pd.merge(batsman_runs11, boundary_runs11, on='match_id', how='inner')

final11
final11 = pd.merge(final11, batsman_running11, on='match_id', how='inner')

final11
BIS_QDK =((final11["batsman_runs"] + final11["boundary runs"]) - (final11["running runs"]) * 0.5) / final11["ball"]
BIS_QDK = sum(BIS_QDK)/len(BIS_QDK)
print("BIS for QDK :" , round(BIS_QDK,2))<jupyter_output>BIS for QDK : 1.99<jupyter_text><NAME> - Toal runs scored by batsman<jupyter_code>samson = MI_RR[(MI_RR["batting_team"] == "Rajasthan Royals")&(MI_RR["batsman"]=="SV Samson")]
samson.iloc[:,4:].head()
samson_runs= samson[samson["wide_runs"]==0]
batsman_runs31 = samson_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs31<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>samson_runs.batsman_runs.unique()
samson_boundaries = samson_runs[(samson_runs["batsman_runs"]==4)|(samson_runs["batsman_runs"]==6)]

boundary_runs31 = pd.DataFrame(samson_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs31.columns = ["boundary runs"]

boundary_runs31<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>samson_running = samson_runs[(samson_runs["batsman_runs"]==1)|(samson_runs["batsman_runs"]==2)|(samson_runs["batsman_runs"]==3)]

batsman_running31 = pd.DataFrame(samson_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running31.columns = ["running runs"]

batsman_running31
final31 = pd.merge(batsman_runs31, boundary_runs31, on='match_id', how='outer')

final31
final31 = pd.merge(final31, batsman_running31, on='match_id', how='outer')

final31<jupyter_output><empty_output><jupyter_text>- Filling null values<jupyter_code>final31["boundary runs"].fillna(0, inplace = True)
final31["running runs"].fillna(0, inplace = True)

final31
final31 = final31[final31["ball"]>=10]

final31
BIS_samson =((final31["batsman_runs"] + final31["boundary runs"]) - (final31["running runs"]) * 0.5) / final31["ball"]
BIS_samson = sum(BIS_samson)/len(BIS_samson)
print("BIS for Samson :" , round(BIS_samson,2))<jupyter_output>BIS for Samson : 2.24<jupyter_text>Pollard   - Total runs scored by the batsman<jupyter_code>pollard = MI_RR[(MI_RR["batting_team"] == "Mumbai Indians")&(MI_RR["batsman"]=="KA Pollard")]
pollard.iloc[:,4:].head()
pollard_runs= pollard[pollard["wide_runs"]==0]
batsman_runs21 = pollard_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs21<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>pollard_runs.batsman_runs.unique()
pollard_boundaries = pollard_runs[(pollard_runs["batsman_runs"]==4)|(pollard_runs["batsman_runs"]==6)]

boundary_runs21 = pd.DataFrame(pollard_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs21.columns = ["boundary runs"]

boundary_runs21<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>pollard_running = pollard_runs[(pollard_runs["batsman_runs"]==1)|(pollard_runs["batsman_runs"]==2)|(pollard_runs["batsman_runs"]==3)]

batsman_running21 = pd.DataFrame(pollard_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running21.columns = ["running runs"]

batsman_running21
final21 = pd.merge(batsman_runs21, boundary_runs21, on='match_id', how='outer')

final21
final21 = pd.merge(final21, batsman_running21, on='match_id', how='outer')

final21<jupyter_output><empty_output><jupyter_text>- Dealing with null values<jupyter_code>final21["boundary runs"].fillna(0, inplace = True)

final21
final21 = final21[final21["ball"]>=10]

final21
BIS_pollard =((final21["batsman_runs"] + final21["boundary runs"]) - (final21["running runs"]) * 0.5) / final21["ball"]
BIS_pollard = sum(BIS_pollard)/len(BIS_pollard)
print("BIS for Pollard :" , round(BIS_pollard,2))<jupyter_output>BIS for Pollard : 1.81<jupyter_text>Ishan Kishan - Total runs scored by the batsman<jupyter_code>kishan = MI_RR[(MI_RR["batting_team"] == "Mumbai Indians")&(MI_RR["batsman"]=="Ishan Kishan")]
kishan.iloc[:,4:].head()
kishan_runs= kishan[kishan["wide_runs"]==0]
batsman_runs22 = kishan_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs22<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>kishan_runs.batsman_runs.unique()
kishan_boundaries = kishan_runs[(kishan_runs["batsman_runs"]==4)|(kishan_runs["batsman_runs"]==6)]

boundary_runs22 = pd.DataFrame(kishan_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs22.columns = ["boundary runs"]

boundary_runs22<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>kishan_running = kishan_runs[(kishan_runs["batsman_runs"]==1)|(kishan_runs["batsman_runs"]==2)|(kishan_runs["batsman_runs"]==3)]

batsman_running22 = pd.DataFrame(kishan_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running22.columns = ["running runs"]

batsman_running22
final22 = pd.merge(batsman_runs22, boundary_runs22, on='match_id', how='outer')

final22
final22 = pd.merge(final22, batsman_running22, on='match_id', how='outer')

final22
final22 = final22[final22["ball"]>=10]

final22
BIS_kishan =((final22["batsman_runs"] + final22["boundary runs"]) - (final22["running runs"]) * 0.5) / final22["ball"]
BIS_kishan = sum(BIS_kishan)/len(BIS_kishan)
print("BIS for Ishan Kishan :" , round(BIS_kishan,2))<jupyter_output>BIS for Ishan Kishan : 1.5<jupyter_text><NAME> - Total runs scored by the batsman<jupyter_code>smith = MI_RR[(MI_RR["batting_team"] == "Rajasthan Royals")&(MI_RR["batsman"]=="SPD Smith")]
smith.iloc[:,4:].head()
smith_runs= smith[smith["wide_runs"]==0]
batsman_runs12 = smith_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs12<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>smith_runs.batsman_runs.unique()
smith_boundaries = smith_runs[(smith_runs["batsman_runs"]==4)|(smith_runs["batsman_runs"]==6)]

boundary_runs12 = pd.DataFrame(smith_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs12.columns = ["boundary runs"]

boundary_runs12<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>smith_running = smith_runs[(smith_runs["batsman_runs"]==1)|(smith_runs["batsman_runs"]==2)|(smith_runs["batsman_runs"]==3)]

batsman_running12 = pd.DataFrame(smith_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running12.columns = ["running runs"]

batsman_running12
final12 = pd.merge(batsman_runs12, boundary_runs12, on='match_id', how='outer')

final12
final12 = pd.merge(final12, batsman_running12, on='match_id', how='outer')

final12
BIS_smith =((final12["batsman_runs"] + final12["boundary runs"]) - (final12["running runs"]) * 0.5) / final12["ball"]
BIS_smith = sum(BIS_smith)/len(BIS_smith)
print("BIS for <NAME> :" , round(BIS_smith,2))<jupyter_output>BIS for <NAME> : 1.31<jupyter_text><NAME> - Total Runs scored by the batsman<jupyter_code>pandya = MI_RR[(MI_RR["batting_team"] == "Mumbai Indians")&(MI_RR["batsman"]=="HH Pandya")]
pandya.iloc[:,4:].head()
pandya_runs= pandya[pandya["wide_runs"]==0]
batsman_runs32 = pandya_runs.groupby(["match_id"]).agg({"batsman_runs":"sum","ball":"count"})
batsman_runs32<jupyter_output><empty_output><jupyter_text>- Runs by boundaries<jupyter_code>pandya_runs.batsman_runs.unique()
pandya_boundaries = pandya_runs[(pandya_runs["batsman_runs"]==4)|(pandya_runs["batsman_runs"]==6)]

boundary_runs32 = pd.DataFrame(pandya_boundaries.groupby(["match_id"])["batsman_runs"].sum())

boundary_runs32.columns = ["boundary runs"]

boundary_runs32<jupyter_output><empty_output><jupyter_text>- Runs by 1,2 and 3<jupyter_code>pandya_running = pandya_runs[(pandya_runs["batsman_runs"]==1)|(pandya_runs["batsman_runs"]==2)|(pandya_runs["batsman_runs"]==3)]

batsman_running32 = pd.DataFrame(pandya_running.groupby(["match_id"])["batsman_runs"].sum())

batsman_running32.columns = ["running runs"]

batsman_running32
final32 = pd.merge(batsman_runs32, boundary_runs32, on='match_id', how='outer')

final32
final32 = pd.merge(final32, batsman_running32, on='match_id', how='outer')

final32
final32["running runs"].fillna(0, inplace = True)

final32
final32 = final32[final32["ball"]>=10]

final32
BIS_pandya =((final32["batsman_runs"] + final32["boundary runs"]) - (final32["running runs"]) * 0.5) / final32["ball"]
BIS_pandya = sum(BIS_pandya)/len(BIS_pandya)
print("BIS for Hardik Pandya :" , round(BIS_pandya,2))<jupyter_output>BIS for Hardik Pandya : 3.0<jupyter_text>From all the above calculation of BIS and taking in consideration the sample size also we can predict that <NAME> and Hardik Pandya are best suitable options for this match  Which individual batsman would have best ratio  QDK<jupyter_code>boundary_runs11 # no of runs scored of boundaries by QDK
batsman_runs11 # total runs scored by QDK
qdk_ratio = pd.merge(boundary_runs11,batsman_runs11 , on = "match_id" , how = "outer")

qdk_ratio["ratio"] = (qdk_ratio["boundary runs"]/qdk_ratio["batsman_runs"])

qdk_ratio
qdk_final_ratio = sum(qdk_ratio["ratio"]/len(qdk_ratio["ratio"]))

print("Average for QDK :",round(qdk_final_ratio*100))<jupyter_output>Average for QDK : 57<jupyter_text>Samson<jupyter_code>boundary_runs31 # no of runs scored of boundaries by Samson
batsman_runs31 # total runs scored by Samson
samson_ratio = pd.merge(batsman_runs31,boundary_runs31, on = "match_id", how = "outer")
samson_ratio["boundary runs"].fillna(0, inplace = True)

samson_ratio
samson_ratio["ratio"] = (samson_ratio["boundary runs"]/samson_ratio["batsman_runs"])

samson_ratio["ratio"].fillna(0, inplace = True)

samson_ratio
sns.distplot(samson_ratio["ratio"])
samson_final_ratio = sum(samson_ratio["ratio"]/len(samson_ratio["ratio"]))

print("Average for Samson :",round(samson_final_ratio*100))<jupyter_output>Average for Samson : 53<jupyter_text>Ishan Kishan<jupyter_code>boundary_runs22 # no of runs scored of boundaries by Ishan
batsman_runs22  # total runs scored by Samson
kishan_ratio = pd.merge(batsman_runs22,boundary_runs22, on = "match_id", how = "outer")
kishan_ratio["ratio"] = (kishan_ratio["boundary runs"]/kishan_ratio["batsman_runs"])

kishan_ratio
kishan_final_ratio = sum(kishan_ratio["ratio"]/len(kishan_ratio["ratio"]))

print("Average for Ishan Kishan :",round(kishan_final_ratio*100))<jupyter_output>Average for Ishan Kishan : 57<jupyter_text>Smith<jupyter_code>batsman_runs12 # total runs scored by Smith
boundary_runs12 # no of runs scored of boundaries by Smith
smith_ratio = pd.merge(batsman_runs12,boundary_runs12, on = "match_id", how = "outer")
smith_ratio["ratio"] = (smith_ratio["boundary runs"]/smith_ratio["batsman_runs"])

smith_ratio
smith_final_ratio = sum(smith_ratio["ratio"]/len(smith_ratio["ratio"]))

print("Average for <NAME> :",round(smith_final_ratio*100))<jupyter_output>Average for <NAME> : 40<jupyter_text>Pollard<jupyter_code>batsman_runs21 # total runs scored by Pollard
boundary_runs21 # no of runs scored of boundaries by Pollard
pollard_ratio = pd.merge(batsman_runs21,boundary_runs21, on = "match_id", how = "outer")
pollard_ratio["boundary runs"].fillna(0, inplace = True)

pollard_ratio
pollard_ratio["ratio"] = (pollard_ratio["boundary runs"]/pollard_ratio["batsman_runs"])

pollard_ratio["ratio"].fillna(0, inplace = True)

pollard_ratio
pollard_final_ratio = sum(pollard_ratio["ratio"]/len(pollard_ratio["ratio"]))

print("Average for Pollard :",round(pollard_final_ratio*100))<jupyter_output>Average for Pollard : 48<jupyter_text>From all the above calculation and analysis of players we can predict <NAME> and <NAME> to have best ratio  Balls RR will take to reach team total of 100 as campared to MI - FOR MUMBAI INDIANS<jupyter_code>mumbai = MI_RR[MI_RR["batting_team"]=="Mumbai Indians"]

mumbai.head()
MI_runs = mumbai.groupby(["match_id","batting_team"]).agg({ "total_runs":"sum"})

print("Runs scored by Mumbai overall :")

MI_runs
a =[]
for value in mumbai.groupby("match_id"):
    count = 0
    suma = 0
    d = list(value[1]["total_runs"])
    print(d)
    for i in d: 
        if suma <100:
            suma=suma+i
            count = count+1
            
    a.append(count)
a
MI_runs["balls for 100"] = a

print("Balls taken by MI for 100 team's run :")
MI_runs
MI_runs.describe().T
sns.distplot(MI_runs["balls for 100"])
plt.figure(figsize=(12,5))
MI_runs["Interval"] = pd.cut(MI_runs["balls for 100"],[50,70,90,110,130])
sns.countplot(MI_runs["Interval"])
plt.title("Ball's taken for 100 by MI")<jupyter_output><empty_output><jupyter_text>- FOR RAJASTHAN ROYALS<jupyter_code>raj = MI_RR[MI_RR["batting_team"]=="Rajasthan Royals"]

raj.head()
RR_runs = raj.groupby(["match_id","batting_team"]).agg({ "total_runs":"sum"})

print("Runs scored by Rajasthan overall :")

RR_runs
a =[]
for value in raj.groupby("match_id"):
    count = 0
    suma = 0
    d = list(value[1]["total_runs"])
    print(d)
    for i in d: 
        if suma <100:
            suma=suma+i
            count = count+1
            
    a.append(count)
a
RR_runs["balls for 100"] = a

print("Balls taken by RR for 100 team's run :")

RR_runs
RR_runs.describe().T
sns.distplot(RR_runs["balls for 100"])
plt.figure(figsize=(12,5))
RR_runs["Interval"] = pd.cut(RR_runs["balls for 100"],[50,70,90,110])
sns.countplot(RR_runs["Interval"])
plt.title("Ball's taken for 100 by RR")<jupyter_output><empty_output><jupyter_text>- Difference<jupyter_code>RR_diff = RR_runs.copy()
MI_diff = MI_runs.copy()

RR_diff.reset_index(inplace = True)
MI_diff.reset_index(inplace = True)

RR_diff = RR_diff.drop(['batting_team','total_runs',"Interval"],axis = 1)
MI_diff = MI_diff.drop(['batting_team','total_runs',"Interval"],axis = 1)

RR_diff.columns = ["match_id","balls for 100 RR"]
MI_diff.columns = ["match_id","balls for 100 MI"]
RR_diff
MI_diff
final = pd.merge(RR_diff, MI_diff, on='match_id', how='inner')

final
final["difference"] = abs(final["balls for 100 MI"] - final["balls for 100 RR"])

final
sns.kdeplot(final["difference"])
print("Average no of difference of balls in scoring 100 runs between RR and MI :{}".format(round(final["difference"].mean())))<jupyter_output>Average no of difference of balls in scoring 100 runs between RR and MI :13<jupyter_text>Confidence Interval Calculation<jupyter_code>final.describe().iloc[:,3:].T
mean = final["difference"].mean()
sd = final["difference"].std()
n = len(final)

n
tstar = 2.064
se = sd/np.sqrt(n)
se
lcb = mean - tstar * se
ucb = mean + tstar * se
lcb = round(lcb)
ucb = round(ucb)

print("95% Confidence Interval for the balls less/more RR can take to reach a total of 100 as campared to MI  :{}".format((lcb, ucb)))<jupyter_output>95% Confidence Interval for the balls less/more RR can take to reach a total of 100 as campared to MI  :(8.0, 18.0)<jupyter_text>BLS  Archer - No of Wicket by bowler<jupyter_code>archer = MI_RR[(MI_RR["bowling_team"] == "Rajasthan Royals")&(MI_RR["bowler"]=="<NAME>")]
archer.iloc[:,4:].head()
archer = archer[archer["dismissal_kind"]!="run out"]
archer = archer[archer["wide_runs"]==0]
archer_wickets = pd.DataFrame(archer.groupby(["match_id"])["dismissal_kind"].count())

archer_wickets.columns = ["wickets"]

archer_wickets<jupyter_output><empty_output><jupyter_text>- No of dot balls by bowler<jupyter_code>archer_dot = archer[archer["total_runs"]==0]
archer_dot_ball = pd.DataFrame(archer_dot.groupby(["match_id"])["total_runs"].count())
archer_dot_ball.columns = ["dot balls"]

archer_dot_ball<jupyter_output><empty_output><jupyter_text>- No of boundary runs given<jupyter_code>archer_bound = archer[(archer["batsman_runs"]==4)|(archer["batsman_runs"]==6)]
archer_bound_run = pd.DataFrame(archer_bound.groupby(["match_id"])["batsman_runs"].sum())

archer_bound_run.columns = ["boundary runs"]

archer_bound_run<jupyter_output><empty_output><jupyter_text>- No of boundaries hit off the bowler<jupyter_code>archer_bound_count = pd.DataFrame(archer_bound.groupby(["match_id"])["batsman_runs"].count())

archer_bound_count.columns = ["boundary count"]

archer_bound_count<jupyter_output><empty_output><jupyter_text>- Total Balls Bowled by the bowler<jupyter_code>archer_total_balls = pd.DataFrame(archer.groupby(["match_id"])["ball"].count())

archer_total_balls
fin11 = pd.merge(archer_total_balls,archer_wickets, on='match_id', how='outer')
fin11 = pd.merge(fin11, archer_dot_ball, on='match_id', how='outer')
fin11 = pd.merge(fin11, archer_bound_run, on='match_id', how='outer')
fin11 = pd.merge(fin11, archer_bound_count, on='match_id', how='outer')
fin11<jupyter_output><empty_output><jupyter_text>- Dealing with null values<jupyter_code>fin11.fillna(0 , inplace = True)

fin11
BLS_archer = ( (fin11["wickets"] + (fin11["dot balls"]*2)) - (fin11["boundary runs"]/fin11["boundary count"]) ) / (fin11["ball"] - (fin11["dot balls"] * 2.5))
BLS_archer = BLS_archer.dropna()
BLS_archer = sum(BLS_archer)/len(BLS_archer)
print("BLS for Archer :",round(BLS_archer,2))<jupyter_output>BLS for Archer : -1.64<jupyter_text><NAME> - No of wickets by bowler<jupyter_code>boult_all = matches[(matches["batting_team"] == "Rajasthan Royals")&(matches["bowler"]=="TA Boult")]
cond1 = boult_all["season"]==2018
cond2 = boult_all["season"]==2019
boult = boult_all[cond1|cond2]

boult.iloc[:,4:].head()
boult = boult[boult["dismissal_kind"]!="run out"]
boult = boult[boult["wide_runs"]==0]

boult.match_id.unique()
boult_wickets = pd.DataFrame(boult.groupby(["match_id"])["dismissal_kind"].count())

boult_wickets.columns = ["wickets"]

boult_wickets<jupyter_output><empty_output><jupyter_text>- No of dot balls by bowler<jupyter_code>boult_dot = boult[boult["total_runs"]==0]
boult_dot_ball = pd.DataFrame(boult_dot.groupby(["match_id"])["total_runs"].count())
boult_dot_ball.columns = ["dot balls"]

boult_dot_ball<jupyter_output><empty_output><jupyter_text>- No of boundary runs given<jupyter_code>boult_bound = boult[(boult["batsman_runs"]==4)|(boult["batsman_runs"]==6)]
boult_bound_run = pd.DataFrame(boult_bound.groupby(["match_id"])["batsman_runs"].sum())

boult_bound_run.columns = ["boundary runs"]

boult_bound_run<jupyter_output><empty_output><jupyter_text>- No of boundaries hit off the bowler<jupyter_code>boult_bound_count = pd.DataFrame(boult_bound.groupby(["match_id"])["batsman_runs"].count())

boult_bound_count.columns = ["boundary count"]

boult_bound_count
boult_total_balls = pd.DataFrame(boult.groupby(["match_id"])["ball"].count())

boult_total_balls
fin12 = pd.merge(boult_total_balls,boult_wickets, on='match_id', how='outer')
fin12 = pd.merge(fin12, boult_dot_ball, on='match_id', how='outer')
fin12 = pd.merge(fin12, boult_bound_run, on='match_id', how='outer')
fin12 = pd.merge(fin12, boult_bound_count, on='match_id', how='outer')
fin12
BLS_boult = ( (fin12["wickets"] + (fin12["dot balls"]*2)) - (fin12["boundary runs"]/fin12["boundary count"]) ) / (fin12["ball"] - (fin12["dot balls"] * 2.5))
BLS_boult = sum(BLS_boult)/len(BLS_boult)
print("BLS for Boult :",round(BLS_boult,2))<jupyter_output>BLS for Boult : -6.12
StarcoderdataJupyterStructuredCleanDedup