import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
df_ipl = pd.read_csv('C:/Users/sathyak/Desktop/ball-by-ball 2008-2020.csv')
df_ipl.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
0 335982 1 6 5 RT Ponting BB McCullum AA Noffke 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
1 335982 1 6 6 BB McCullum RT Ponting AA Noffke 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
2 335982 1 7 1 BB McCullum RT Ponting Z Khan 0 0 0 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
3 335982 1 7 2 BB McCullum RT Ponting Z Khan 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
4 335982 1 7 3 RT Ponting BB McCullum Z Khan 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
df_ipl.tail()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
193463 1237181 1 12 5 RR Pant SS Iyer NM Coulter-Nile 0 0 0 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193464 1237181 1 12 6 RR Pant SS Iyer NM Coulter-Nile 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193465 1237181 1 13 1 RR Pant SS Iyer KH Pandya 0 1 1 0 0 NaN NaN NaN wides Delhi Capitals Mumbai Indians
193466 1237181 1 13 2 RR Pant SS Iyer KH Pandya 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193467 1237181 1 13 3 SS Iyer RR Pant KH Pandya 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
df_ipl.shape
(193468, 18)
df_ipl.groupby(["batting_team"])["total_runs"].sum().sort_values(ascending = False)
batting_team
Mumbai Indians                 32286
Royal Challengers Bangalore    30214
Kings XI Punjab                30017
Kolkata Knight Riders          29383
Chennai Super Kings            28363
Rajasthan Royals               24507
Delhi Daredevils               24285
Sunrisers Hyderabad            19332
Deccan Chargers                11463
Pune Warriors                   6358
Delhi Capitals                  5296
Gujarat Lions                   4856
Rising Pune Supergiant          2470
Rising Pune Supergiants         2063
Kochi Tuskers Kerala            1901
Name: total_runs, dtype: int64
df_kkr = df_ipl[df_ipl["batting_team"]=='Kolkata Knight Riders']
df_kkr.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
0 335982 1 6 5 RT Ponting BB McCullum AA Noffke 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
1 335982 1 6 6 BB McCullum RT Ponting AA Noffke 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
2 335982 1 7 1 BB McCullum RT Ponting Z Khan 0 0 0 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
3 335982 1 7 2 BB McCullum RT Ponting Z Khan 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
4 335982 1 7 3 RT Ponting BB McCullum Z Khan 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Royal Challengers Bangalore
df_kkr.tail()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
191905 1216545 2 17 3 Shubman Gill EJG Morgan T Natarajan 0 0 0 0 0 NaN NaN NaN NaN Kolkata Knight Riders Sunrisers Hyderabad
191906 1216545 2 17 4 Shubman Gill EJG Morgan T Natarajan 0 1 1 0 0 NaN NaN NaN wides Kolkata Knight Riders Sunrisers Hyderabad
191907 1216545 2 17 5 Shubman Gill EJG Morgan T Natarajan 1 0 1 0 0 NaN NaN NaN NaN Kolkata Knight Riders Sunrisers Hyderabad
191908 1216545 2 17 6 EJG Morgan Shubman Gill T Natarajan 6 0 6 0 0 NaN NaN NaN NaN Kolkata Knight Riders Sunrisers Hyderabad
191909 1216545 2 17 7 EJG Morgan Shubman Gill T Natarajan 4 0 4 0 0 NaN NaN NaN NaN Kolkata Knight Riders Sunrisers Hyderabad
df_kkr.shape
(22554, 18)
kkr_totalruns = df_kkr['total_runs'].sum()
kkr_totalruns
29383
kkr_batsman = pd.DataFrame((df_kkr.groupby(['batsman'])['batsman_runs'].sum()/kkr_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
kkr_batsman
batsman_runs
batsman
G Gambhir 10.329102
RV Uthappa 8.300718
YK Pathan 6.442501
AD Russell 4.965456
JH Kallis 4.407310
... ...
SE Bond 0.003403
HF Gurney 0.003403
CK Langeveldt 0.000000
Y Prithvi Raj 0.000000
JL Denly 0.000000

101 rows × 1 columns

kkr_runs1=kkr_batsman[:14].copy()
kkr_runs1.reset_index(level=0, inplace=True)
kkr_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[kkr_batsman['batsman_runs'][14:].sum()]})
kkr_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_kkr['total_runs'] - df_kkr['batsman_runs']).sum()/kkr_totalruns)*100})
kkr_runs3
batsman batsman_runs
0 Extras 5.503182
kkr_runs1.head()
batsman batsman_runs
0 G Gambhir 10.329102
1 RV Uthappa 8.300718
2 YK Pathan 6.442501
3 AD Russell 4.965456
4 JH Kallis 4.407310
kkr_runs2
batsman batsman_runs
0 Others 28.707076
kkr=pd.concat([kkr_runs1,kkr_runs2,kkr_runs3])
kkr.head()
batsman batsman_runs
0 G Gambhir 10.329102
1 RV Uthappa 8.300718
2 YK Pathan 6.442501
3 AD Russell 4.965456
4 JH Kallis 4.407310
kkr.tail()
batsman batsman_runs
11 KD Karthik 3.131062
12 SP Narine 3.035769
13 BB McCullum 3.001736
0 Others 28.707076
0 Extras 5.503182
kkr.shape
(16, 2)
kkr=kkr.set_index('batsman')
kkr.head()
batsman_runs
batsman
G Gambhir 10.329102
RV Uthappa 8.300718
YK Pathan 6.442501
AD Russell 4.965456
JH Kallis 4.407310
kkr.tail()
batsman_runs
batsman
KD Karthik 3.131062
SP Narine 3.035769
BB McCullum 3.001736
Others 28.707076
Extras 5.503182
kkr
batsman_runs
batsman
G Gambhir 10.329102
RV Uthappa 8.300718
YK Pathan 6.442501
AD Russell 4.965456
JH Kallis 4.407310
CA Lynn 4.335840
MK Pandey 4.322227
SC Ganguly 3.508832
MK Tiwary 3.410135
N Rana 3.403328
Shubman Gill 3.195725
KD Karthik 3.131062
SP Narine 3.035769
BB McCullum 3.001736
Others 28.707076
Extras 5.503182
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
kkr.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show()
df_rr = df_ipl[df_ipl["batting_team"]=='Rajasthan Royals']
df_rr.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
473 335984 1 0 2 T Kohli YK Pathan GD McGrath 0 0 0 0 0 NaN NaN NaN NaN Rajasthan Royals Delhi Daredevils
474 335984 1 0 3 T Kohli YK Pathan GD McGrath 0 0 0 0 0 NaN NaN NaN NaN Rajasthan Royals Delhi Daredevils
475 335984 1 0 4 T Kohli YK Pathan GD McGrath 0 1 1 0 0 NaN NaN NaN wides Rajasthan Royals Delhi Daredevils
476 335984 1 0 6 T Kohli YK Pathan GD McGrath 0 0 0 0 0 NaN NaN NaN NaN Rajasthan Royals Delhi Daredevils
477 335984 1 0 7 T Kohli YK Pathan GD McGrath 6 0 6 0 0 NaN NaN NaN NaN Rajasthan Royals Delhi Daredevils
rr_totalruns = df_rr['total_runs'].sum()
rr_totalruns
24507
rr_batsman = pd.DataFrame((df_rr.groupby(['batsman'])['batsman_runs'].sum()/rr_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
rr_batsman
batsman_runs
batsman
AM Rahane 11.466112
SR Watson 9.678867
SV Samson 7.781450
R Dravid 5.206676
JC Buttler 4.843514
... ...
J Theron 0.004080
R Shukla 0.004080
KW Richardson 0.004080
ND Doshi 0.000000
JDP Oram 0.000000

105 rows × 1 columns

rr_runs1=rr_batsman[:14].copy()
rr_runs1.reset_index(level=0, inplace=True)
rr_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[rr_batsman['batsman_runs'][14:].sum()]})
rr_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_rr['total_runs'] - df_rr['batsman_runs']).sum()/rr_totalruns)*100})
rr_runs1.head()
batsman batsman_runs
0 AM Rahane 11.466112
1 SR Watson 9.678867
2 SV Samson 7.781450
3 R Dravid 5.206676
4 JC Buttler 4.843514
rr_runs2.head()
batsman batsman_runs
0 Others 30.750398
rr=pd.concat([rr_runs1,rr_runs2,rr_runs3])
rr.head()
batsman batsman_runs
0 AM Rahane 11.466112
1 SR Watson 9.678867
2 SV Samson 7.781450
3 R Dravid 5.206676
4 JC Buttler 4.843514
rr.tail()
batsman batsman_runs
11 NV Ojha 2.223854
12 KK Nair 2.085119
13 RA Jadeja 1.754601
0 Others 30.750398
0 Extras 4.819031
rr=rr.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
rr.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show()
df_csk = df_ipl[df_ipl["batting_team"]=='Chennai Super Kings']
df_csk.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
227 335983 1 19 5 MEK Hussey S Badrinath JR Hopes 6 0 6 0 0 NaN NaN NaN NaN Chennai Super Kings Kings XI Punjab
228 335983 1 19 6 MEK Hussey S Badrinath JR Hopes 2 0 2 0 0 NaN NaN NaN NaN Chennai Super Kings Kings XI Punjab
242 335983 1 9 5 MEK Hussey SK Raina K Goel 0 0 0 0 0 NaN NaN NaN NaN Chennai Super Kings Kings XI Punjab
243 335983 1 9 6 MEK Hussey SK Raina K Goel 1 0 1 0 0 NaN NaN NaN NaN Chennai Super Kings Kings XI Punjab
244 335983 1 10 1 MEK Hussey SK Raina PP Chawla 6 0 6 0 0 NaN NaN NaN NaN Chennai Super Kings Kings XI Punjab
df_csk.tail()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
191758 1216544 2 12 3 RD Gaikwad AT Rayudu Washington Sundar 1 0 1 0 0 NaN NaN NaN NaN Chennai Super Kings Royal Challengers Bangalore
191759 1216544 2 12 4 AT Rayudu RD Gaikwad Washington Sundar 1 0 1 0 0 NaN NaN NaN NaN Chennai Super Kings Royal Challengers Bangalore
191760 1216544 2 13 3 AT Rayudu RD Gaikwad YS Chahal 0 0 0 0 1 bowled AT Rayudu NaN NaN Chennai Super Kings Royal Challengers Bangalore
191761 1216544 2 13 1 AT Rayudu RD Gaikwad YS Chahal 1 0 1 0 0 NaN NaN NaN NaN Chennai Super Kings Royal Challengers Bangalore
191762 1216544 2 13 2 RD Gaikwad AT Rayudu YS Chahal 1 0 1 0 0 NaN NaN NaN NaN Chennai Super Kings Royal Challengers Bangalore
csk_totalruns = df_csk['total_runs'].sum()
csk_totalruns
28363
csk_batsman = pd.DataFrame((df_csk.groupby(['batsman'])['batsman_runs'].sum()/csk_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
csk_batsman.head()
batsman_runs
batsman
SK Raina 15.960935
MS Dhoni 14.307372
F du Plessis 7.361704
MEK Hussey 6.233473
M Vijay 6.021930
csk_runs1=csk_batsman[:14].copy()
csk_runs1.reset_index(level=0, inplace=True)
csk_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[csk_batsman['batsman_runs'][14:].sum()]})
csk_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_csk['total_runs'] - df_csk['batsman_runs']).sum()/csk_totalruns)*100})
csk_runs1.head()
batsman batsman_runs
0 SK Raina 15.960935
1 MS Dhoni 14.307372
2 F du Plessis 7.361704
3 MEK Hussey 6.233473
4 M Vijay 6.021930
csk_runs2.head()
batsman batsman_runs
0 Others 10.919155
csk=pd.concat([csk_runs1,csk_runs2,csk_runs3])
csk.head()
batsman batsman_runs
0 SK Raina 15.960935
1 MS Dhoni 14.307372
2 F du Plessis 7.361704
3 MEK Hussey 6.233473
4 M Vijay 6.021930
csk.tail()
batsman batsman_runs
11 DJ Bravo 3.293023
12 BB McCullum 2.965131
13 JA Morkel 2.915771
0 Others 10.919155
0 Extras 4.971265
csk=csk.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
csk.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show()
df_mi = df_ipl[df_ipl["batting_team"]=='Mumbai Indians']
df_mi.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
692 335985 1 0 2 L Ronchi ST Jayasuriya P Kumar 4 0 4 0 0 NaN NaN NaN NaN Mumbai Indians Royal Challengers Bangalore
693 335985 1 0 1 L Ronchi ST Jayasuriya P Kumar 0 0 0 0 0 NaN NaN NaN NaN Mumbai Indians Royal Challengers Bangalore
694 335985 1 0 6 L Ronchi ST Jayasuriya P Kumar 0 0 0 0 0 NaN NaN NaN NaN Mumbai Indians Royal Challengers Bangalore
695 335985 1 0 3 L Ronchi ST Jayasuriya P Kumar 0 0 0 0 0 NaN NaN NaN NaN Mumbai Indians Royal Challengers Bangalore
696 335985 1 0 4 L Ronchi ST Jayasuriya P Kumar 0 0 0 0 0 NaN NaN NaN NaN Mumbai Indians Royal Challengers Bangalore
df_mi.tail()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
193372 1237181 2 17 6 HH Pandya Ishan Kishan K Rabada 1 0 1 0 0 NaN NaN NaN NaN Mumbai Indians Delhi Capitals
193373 1237181 2 18 1 HH Pandya Ishan Kishan A Nortje 1 0 1 0 0 NaN NaN NaN NaN Mumbai Indians Delhi Capitals
193374 1237181 2 18 2 Ishan Kishan HH Pandya A Nortje 1 0 1 0 0 NaN NaN NaN NaN Mumbai Indians Delhi Capitals
193375 1237181 2 18 3 HH Pandya Ishan Kishan A Nortje 0 0 0 0 1 caught HH Pandya AM Rahane NaN Mumbai Indians Delhi Capitals
193376 1237181 2 18 4 KH Pandya Ishan Kishan A Nortje 1 0 1 0 0 NaN NaN NaN NaN Mumbai Indians Delhi Capitals
mi_totalruns = df_mi['total_runs'].sum()
mi_totalruns
32286
mi_batsman = pd.DataFrame((df_mi.groupby(['batsman'])['batsman_runs'].sum()/mi_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
mi_batsman.head(10)
batsman_runs
batsman
RG Sharma 12.575110
KA Pollard 9.363191
AT Rayudu 7.483120
SR Tendulkar 7.229140
SA Yadav 4.385802
HH Pandya 4.178282
LMP Simmons 3.342006
Q de Kock 3.196432
KH Pandya 3.097318
PA Patel 2.821656
mi_runs1=mi_batsman[:14].copy()
mi_runs1.reset_index(level=0, inplace=True)
mi_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[mi_batsman['batsman_runs'][14:].sum()]})
mi_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_mi['total_runs'] - df_mi['batsman_runs']).sum()/mi_totalruns)*100})
mi_runs1.head()
batsman batsman_runs
0 RG Sharma 12.575110
1 KA Pollard 9.363191
2 AT Rayudu 7.483120
3 SR Tendulkar 7.229140
4 SA Yadav 4.385802
mi_runs2.head()
batsman batsman_runs
0 Others 27.008611
mi=pd.concat([mi_runs1,mi_runs2,mi_runs3])
mi.tail()
batsman batsman_runs
11 Harbhajan Singh 2.474757
12 ST Jayasuriya 2.378740
13 KD Karthik 2.316794
0 Others 27.008611
0 Extras 5.386236
mi=mi.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
mi.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
df_rcb = df_ipl[df_ipl["batting_team"]=='Royal Challengers Bangalore']
df_rcb.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
121 335982 2 6 2 CL White MV Boucher AB Agarkar 0 0 0 0 0 NaN NaN NaN NaN Royal Challengers Bangalore Kolkata Knight Riders
122 335982 2 6 3 CL White MV Boucher AB Agarkar 1 0 1 0 0 NaN NaN NaN NaN Royal Challengers Bangalore Kolkata Knight Riders
123 335982 2 6 4 MV Boucher CL White AB Agarkar 0 1 1 0 0 NaN NaN NaN wides Royal Challengers Bangalore Kolkata Knight Riders
124 335982 2 6 5 MV Boucher CL White AB Agarkar 0 1 1 0 0 NaN NaN NaN wides Royal Challengers Bangalore Kolkata Knight Riders
125 335982 2 6 6 MV Boucher CL White AB Agarkar 0 0 0 0 0 NaN NaN NaN NaN Royal Challengers Bangalore Kolkata Knight Riders
df_rcb.shape
(22706, 18)
rcb_totalruns = df_rcb['total_runs'].sum()
rcb_totalruns
30214
rcb_batsman = pd.DataFrame((df_rcb.groupby(['batsman'])['batsman_runs'].sum()/rcb_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
rcb_batsman.head()
batsman_runs
batsman
V Kohli 19.454557
AB de Villiers 13.828027
CH Gayle 10.468657
JH Kallis 3.746608
R Dravid 2.972132
rcb_runs1=rcb_batsman[:14].copy()
rcb_runs1.reset_index(level=0, inplace=True)
rcb_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[rcb_batsman['batsman_runs'][14:].sum()]})
rcb_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_rcb['total_runs'] - df_rcb['batsman_runs']).sum()/rcb_totalruns)*100})
rcb=pd.concat([rcb_runs1,rcb_runs2,rcb_runs3])
rcb.head()
batsman batsman_runs
0 V Kohli 19.454557
1 AB de Villiers 13.828027
2 CH Gayle 10.468657
3 JH Kallis 3.746608
4 R Dravid 2.972132
rcb.tail()
batsman batsman_runs
11 D Padikkal 1.565499
12 MA Agarwal 1.433110
13 MK Pandey 1.380155
0 Others 28.797908
0 Extras 4.875223
rcb=rcb.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
rcb.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
df_kxip = df_ipl[df_ipl["batting_team"]=='Kings XI Punjab']
df_kxip.head()
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
225 335983 2 0 1 K Goel JR Hopes JDP Oram 4 0 4 0 0 NaN NaN NaN NaN Kings XI Punjab Chennai Super Kings
226 335983 2 0 2 K Goel JR Hopes JDP Oram 0 0 0 0 0 NaN NaN NaN NaN Kings XI Punjab Chennai Super Kings
229 335983 2 0 5 JR Hopes K Goel JDP Oram 0 0 0 0 0 NaN NaN NaN NaN Kings XI Punjab Chennai Super Kings
230 335983 2 0 6 JR Hopes K Goel JDP Oram 4 0 4 0 0 NaN NaN NaN NaN Kings XI Punjab Chennai Super Kings
231 335983 2 1 1 K Goel JR Hopes MS Gony 1 0 1 0 0 NaN NaN NaN NaN Kings XI Punjab Chennai Super Kings
kxip_totalruns = df_kxip['total_runs'].sum()
kxip_totalruns
30017
kxip_batsman = pd.DataFrame((df_kxip.groupby(['batsman'])['batsman_runs'].sum()/kxip_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
kxip_batsman.head()
batsman_runs
batsman
SE Marsh 8.251991
KL Rahul 6.403038
DA Miller 6.163174
GJ Maxwell 4.310890
CH Gayle 3.817837
kxip_runs1=kxip_batsman[:14].copy()
kxip_runs1.reset_index(level=0, inplace=True)
kxip_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[kxip_batsman['batsman_runs'][14:].sum()]})
kxip_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_kxip['total_runs'] - df_kxip['batsman_runs']).sum()/kxip_totalruns)*100})
kxip=pd.concat([kxip_runs1,kxip_runs2,kxip_runs3])
kxip.tail()
batsman batsman_runs
11 AC Gilchrist 2.828397
12 DPMD Jayawardene 2.788420
13 M Vijay 2.345338
0 Others 38.121731
0 Extras 5.067129
kxip=kxip.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
kxip.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
df_dc = df_ipl[df_ipl["batting_team"]=='Delhi Daredevils'|'Delhi Capitals']
  File "<ipython-input-118-59bbe77cadbd>", line 1
    df_dc = df_ipl[df_ipl["batting_team"]=='Delhi Daredevils'||'Delhi Capitals']
                                                              ^
SyntaxError: invalid syntax
df_dc = df_ipl[df_ipl['batting_team'].isin(['Delhi Daredevils', 'Delhi Capitals']) ]
df_dc
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
485 335984 2 8 4 S Dhawan G Gambhir SK Warne 0 0 0 0 0 NaN NaN NaN NaN Delhi Daredevils Rajasthan Royals
486 335984 2 8 5 S Dhawan G Gambhir SK Warne 1 0 1 0 0 NaN NaN NaN NaN Delhi Daredevils Rajasthan Royals
487 335984 2 8 6 G Gambhir S Dhawan SK Warne 1 0 1 0 0 NaN NaN NaN NaN Delhi Daredevils Rajasthan Royals
488 335984 2 9 1 G Gambhir S Dhawan YK Pathan 0 0 0 0 0 NaN NaN NaN NaN Delhi Daredevils Rajasthan Royals
489 335984 2 9 2 G Gambhir S Dhawan YK Pathan 0 1 1 0 0 NaN NaN NaN wides Delhi Daredevils Rajasthan Royals
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
193463 1237181 1 12 5 RR Pant SS Iyer NM Coulter-Nile 0 0 0 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193464 1237181 1 12 6 RR Pant SS Iyer NM Coulter-Nile 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193465 1237181 1 13 1 RR Pant SS Iyer KH Pandya 0 1 1 0 0 NaN NaN NaN wides Delhi Capitals Mumbai Indians
193466 1237181 1 13 2 RR Pant SS Iyer KH Pandya 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians
193467 1237181 1 13 3 SS Iyer RR Pant KH Pandya 1 0 1 0 0 NaN NaN NaN NaN Delhi Capitals Mumbai Indians

22788 rows × 18 columns

dc_totalruns = df_dc['total_runs'].sum()
dc_totalruns
29581
dc_batsman = pd.DataFrame((df_dc.groupby(['batsman'])['batsman_runs'].sum()/dc_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
dc_batsman
batsman_runs
batsman
SS Iyer 7.437206
V Sehwag 7.349312
RR Pant 7.028160
S Dhawan 4.999831
DA Warner 4.851087
... ...
S Lamichhane 0.000000
S Ladda 0.000000
DR Sams 0.000000
Sunny Gupta 0.000000
AB Dinda 0.000000

117 rows × 1 columns

dc_runs1=dc_batsman[:14].copy()
dc_runs1.reset_index(level=0, inplace=True)
dc_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[dc_batsman['batsman_runs'][14:].sum()]})
dc_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_dc['total_runs'] - df_dc['batsman_runs']).sum()/dc_totalruns)*100})
dc=pd.concat([dc_runs1,dc_runs2,dc_runs3])
dc.head()
batsman batsman_runs
0 SS Iyer 7.437206
1 V Sehwag 7.349312
2 RR Pant 7.028160
3 S Dhawan 4.999831
4 DA Warner 4.851087
dc=dc.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
dc.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>
df_ipl.groupby(["batting_team"])["total_runs"].sum().sort_values(ascending = False)
batting_team
Mumbai Indians                 32286
Royal Challengers Bangalore    30214
Kings XI Punjab                30017
Kolkata Knight Riders          29383
Chennai Super Kings            28363
Rajasthan Royals               24507
Delhi Daredevils               24285
Sunrisers Hyderabad            19332
Deccan Chargers                11463
Pune Warriors                   6358
Delhi Capitals                  5296
Gujarat Lions                   4856
Rising Pune Supergiant          2470
Rising Pune Supergiants         2063
Kochi Tuskers Kerala            1901
Name: total_runs, dtype: int64
df_srh = df_ipl[df_ipl['batting_team'].isin(['Sunrisers Hyderabad', 'Deccan Chargers']) ]
df_srh
id inning over ball batsman non_striker bowler batsman_runs extra_runs total_runs non_boundary is_wicket dismissal_kind player_dismissed fielder extras_type batting_team bowling_team
970 335986 1 12 1 AS Yadav A Symonds DJ Hussey 1 0 1 0 0 NaN NaN NaN NaN Deccan Chargers Kolkata Knight Riders
971 335986 1 12 2 A Symonds AS Yadav DJ Hussey 1 0 1 0 0 NaN NaN NaN NaN Deccan Chargers Kolkata Knight Riders
972 335986 1 12 3 AS Yadav A Symonds DJ Hussey 0 0 0 0 0 NaN NaN NaN NaN Deccan Chargers Kolkata Knight Riders
973 335986 1 12 4 AS Yadav A Symonds DJ Hussey 1 0 1 0 0 NaN NaN NaN NaN Deccan Chargers Kolkata Knight Riders
974 335986 1 12 5 A Symonds AS Yadav DJ Hussey 0 0 0 0 0 NaN NaN NaN NaN Deccan Chargers Kolkata Knight Riders
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
193228 1237180 2 18 7 S Nadeem Sandeep Sharma K Rabada 0 0 0 0 0 NaN NaN NaN NaN Sunrisers Hyderabad Delhi Capitals
193229 1237180 2 19 5 Sandeep Sharma S Nadeem A Nortje 0 0 0 0 0 NaN NaN NaN NaN Sunrisers Hyderabad Delhi Capitals
193230 1237180 2 19 2 S Nadeem Sandeep Sharma A Nortje 1 0 1 0 0 NaN NaN NaN NaN Sunrisers Hyderabad Delhi Capitals
193231 1237180 2 19 3 Sandeep Sharma S Nadeem A Nortje 1 0 1 0 0 NaN NaN NaN NaN Sunrisers Hyderabad Delhi Capitals
193232 1237180 2 19 4 S Nadeem Sandeep Sharma A Nortje 1 0 1 0 0 NaN NaN NaN NaN Sunrisers Hyderabad Delhi Capitals

23860 rows × 18 columns

srh_totalruns = df_srh['total_runs'].sum()
srh_batsman = pd.DataFrame((df_srh.groupby(['batsman'])['batsman_runs'].sum()/srh_totalruns)*100).sort_values(by='batsman_runs',ascending=False)
srh_batsman
batsman_runs
batsman
DA Warner 12.401364
S Dhawan 11.323267
KS Williamson 5.257347
AC Gilchrist 3.961682
RG Sharma 3.799318
... ...
KK Ahmed 0.000000
Harmeet Singh 0.000000
V Pratap Singh 0.000000
MJ Lumb 0.000000
CJ Jordan 0.000000

109 rows × 1 columns

srh_runs1=srh_batsman[:14].copy()
srh_runs1.reset_index(level=0, inplace=True)
srh_runs2=pd.DataFrame(data={'batsman':['Others'],'batsman_runs':[srh_batsman['batsman_runs'][14:].sum()]})
srh_runs3 = pd.DataFrame(data={'batsman':['Extras'],'batsman_runs':((df_srh['total_runs'] - df_srh['batsman_runs']).sum()/srh_totalruns)*100})
srh=pd.concat([srh_runs1,srh_runs2,srh_runs3])
srh=srh.set_index('batsman')
wp = { 'linewidth' : 2, 'edgecolor' : "white" }
colors = ['#9e8600','#a38b00','#a88f00','#b39800','#b89c00','#bda000','#c7a900','#ccad00','#d1b200','#dbba00','#e0bf00','#e6c300','#f0cc00','#f5d000','#947e00'] 
srh.plot.pie(y='batsman_runs',wedgeprops = wp,figsize=(15,15),
                                  startangle = 90,colors = colors,
                                  textprops = dict(color ="Black"),autopct='%1.1f%%')
plt.tight_layout()
plt.show
<function matplotlib.pyplot.show(*args, **kw)>