IPL

temp-162419151367394675
In [133]:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
In [134]:
matches = pd.read_csv("matches.csv")
matches.drop(axis = 1, columns = ["dl_applied", "umpire1", "umpire2", "umpire3"], inplace = True)
matches.head()
Out[134]:
id season city date team1 team2 toss_winner toss_decision result winner win_by_runs win_by_wickets player_of_match venue
0 1 2017 Hyderabad 2017-04-05 Sunrisers Hyderabad Royal Challengers Bangalore Royal Challengers Bangalore field normal Sunrisers Hyderabad 35 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal
1 2 2017 Pune 2017-04-06 Mumbai Indians Rising Pune Supergiant Rising Pune Supergiant field normal Rising Pune Supergiant 0 7 SPD Smith Maharashtra Cricket Association Stadium
2 3 2017 Rajkot 2017-04-07 Gujarat Lions Kolkata Knight Riders Kolkata Knight Riders field normal Kolkata Knight Riders 0 10 CA Lynn Saurashtra Cricket Association Stadium
3 4 2017 Indore 2017-04-08 Rising Pune Supergiant Kings XI Punjab Kings XI Punjab field normal Kings XI Punjab 0 6 GJ Maxwell Holkar Cricket Stadium
4 5 2017 Bangalore 2017-04-08 Royal Challengers Bangalore Delhi Daredevils Royal Challengers Bangalore bat normal Royal Challengers Bangalore 15 0 KM Jadhav M Chinnaswamy Stadium
In [135]:
matches[matches["player_of_match"].isnull()]
matches.drop(index = [300, 545, 570,744], inplace = True)
In [136]:
matches.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 752 entries, 0 to 755
Data columns (total 14 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   id               752 non-null    int64 
 1   season           752 non-null    int64 
 2   city             745 non-null    object
 3   date             752 non-null    object
 4   team1            752 non-null    object
 5   team2            752 non-null    object
 6   toss_winner      752 non-null    object
 7   toss_decision    752 non-null    object
 8   result           752 non-null    object
 9   winner           752 non-null    object
 10  win_by_runs      752 non-null    int64 
 11  win_by_wickets   752 non-null    int64 
 12  player_of_match  752 non-null    object
 13  venue            752 non-null    object
dtypes: int64(4), object(10)
memory usage: 88.1+ KB
In [ ]:

In [137]:
deliveries = pd.read_csv("deliveries.csv")
In [138]:
deliveries["player_dismissed"].fillna(value = "None", inplace = True)
deliveries["dismissal_kind"].fillna(value = "None", inplace = True)
deliveries["fielder"].fillna(value = "None", inplace = True)
deliveries.head()
Out[138]:
match_id inning batting_team bowling_team over ball batsman non_striker bowler is_super_over ... bye_runs legbye_runs noball_runs penalty_runs batsman_runs extra_runs total_runs player_dismissed dismissal_kind fielder
0 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 1 DA Warner S Dhawan TS Mills 0 ... 0 0 0 0 0 0 0 None None None
1 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 2 DA Warner S Dhawan TS Mills 0 ... 0 0 0 0 0 0 0 None None None
2 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 3 DA Warner S Dhawan TS Mills 0 ... 0 0 0 0 4 0 4 None None None
3 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 4 DA Warner S Dhawan TS Mills 0 ... 0 0 0 0 0 0 0 None None None
4 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 5 DA Warner S Dhawan TS Mills 0 ... 0 0 0 0 0 2 2 None None None

5 rows × 21 columns

In [139]:
deliveries.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 179078 entries, 0 to 179077
Data columns (total 21 columns):
 #   Column            Non-Null Count   Dtype 
---  ------            --------------   ----- 
 0   match_id          179078 non-null  int64 
 1   inning            179078 non-null  int64 
 2   batting_team      179078 non-null  object
 3   bowling_team      179078 non-null  object
 4   over              179078 non-null  int64 
 5   ball              179078 non-null  int64 
 6   batsman           179078 non-null  object
 7   non_striker       179078 non-null  object
 8   bowler            179078 non-null  object
 9   is_super_over     179078 non-null  int64 
 10  wide_runs         179078 non-null  int64 
 11  bye_runs          179078 non-null  int64 
 12  legbye_runs       179078 non-null  int64 
 13  noball_runs       179078 non-null  int64 
 14  penalty_runs      179078 non-null  int64 
 15  batsman_runs      179078 non-null  int64 
 16  extra_runs        179078 non-null  int64 
 17  total_runs        179078 non-null  int64 
 18  player_dismissed  179078 non-null  object
 19  dismissal_kind    179078 non-null  object
 20  fielder           179078 non-null  object
dtypes: int64(13), object(8)
memory usage: 28.7+ MB
In [140]:
deliveries[deliveries["is_super_over"] != 0].match_id.nunique() # matches with super over
Out[140]:
7
In [141]:
#No. of matches played in each ipl season
plt.figure(figsize = (10,8))
sns.countplot(x = matches.season)
plt.ylabel("No. of matches played")
plt.xlabel("Season");
In [142]:
#no. of matches won by a team
plt.figure(figsize = (12,10))
sns.countplot(x= matches.winner)
plt.xlabel("Teams")
plt.xticks(rotation = 70)
plt.ylabel("Matches won");
In [143]:
#match result- bowl first/bat first (pie)
mt = matches[["toss_decision", "win_by_runs"]]
s = mt[mt["win_by_runs"] > 0].toss_decision.value_counts().sum()
r= ((mt[mt["win_by_runs"] > 0].toss_decision.value_counts()*100/s)).round(1)
plt.figure(figsize = (10,8))
plt.pie(r, autopct ='%1.1f%%', labels = ["Bowl First", "Bat First"]);
In [144]:
#number of matches won by batting or bowlinf first

mini_m = matches[["season", "winner", "toss_decision"]]
mini_m
ht = mini_m.season.value_counts()
plt.figure(figsize = (10,8))
sns.countplot(x = "season", data = mini_m, hue = "toss_decision")
plt.ylabel("Matches Won");
In [145]:
#Toss Decision
plt.figure(figsize = (10,8))
matches.toss_decision.value_counts().plot(kind = "pie", autopct ='%1.1f%%' );
In [146]:
# no. of matches won by toss result
mini_m
plt.figure(figsize = (10,8))
sns.countplot(x = "season", data = mini_m, hue = "toss_decision", palette="Set3")
plt.ylabel("Matches Won");
In [147]:
#top players of the match winner
top_p = matches["player_of_match"].value_counts().head(10)
plt.figure(figsize = (10,8))
plt.xticks(rotation = 90)
color = ["red","green","yellow","violet","blue","brown","silver","pink","black","orange"]
plt.bar(x = top_p.index, height = top_p, color = color);
In [148]:
#no. of fours hit by a player
players = deliveries[["batsman","batsman_runs"]] 
ply_graph = players[players.batsman_runs == 4].batsman.value_counts().head(10)
plt.figure(figsize = (10,8))
plt.xticks(rotation =70)
plt.bar(x = ply_graph.index, height = ply_graph)
plt.xlabel("Players")
plt.ylabel("No. of Four");
In [149]:
#no . of fours hit in each season
m1 = matches[["id","season"]]
m2 = deliveries[["match_id", "batsman_runs"]]
merged = m1.merge(m2, how = "inner", left_on = "id", right_on = "match_id")
m3 =merged[merged["batsman_runs"] == 4]
plt.figure(figsize=(10,8))
sns.countplot(x = "season", data = m3)
plt.xlabel("Seasons")
plt.ylabel("No. of Four");
In [150]:
#number of six hits by a player
ply_graph1 = players[players.batsman_runs == 6].batsman.value_counts().head(10)
plt.figure(figsize = (10,8))
plt.xticks(rotation =70)
plt.bar(x = ply_graph1.index, height = ply_graph1)
plt.xlabel("Players")
plt.ylabel("No. of Six");
In [151]:
#number of six hits in each season
m4 =merged[merged["batsman_runs"] == 6]
plt.figure(figsize=(10,8))
sns.countplot(x = "season", data = m4)
plt.xlabel("Seasons")
plt.ylabel("No. of Four");
In [152]:
#dismissal in ipl
dis = deliveries["dismissal_kind"].value_counts().to_frame().drop("None")
plt.figure(figsize = (10,8))
dis.plot(kind = "bar")
plt.ylabel("Count");
<Figure size 720x576 with 0 Axes>
In [178]:
# ipl most wicket taking bowlers 
blr = deliveries[deliveries.dismissal_kind != "None"]
blr[["bowler", "dismissal_kind"]].value_counts().to_frame().head(10)
Out[178]:
0
bowler dismissal_kind
DJ Bravo caught 113
SL Malinga caught 91
UT Yadav caught 89
A Mishra caught 89
Harbhajan Singh caught 84
B Kumar caught 84
R Vinay Kumar caught 82
R Ashwin caught 78
A Nehra caught 76
PP Chawla caught 72
In [ ]:

In [ ]:

Comments