IPL
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]:
In [135]:
matches[matches["player_of_match"].isnull()]
matches.drop(index = [300, 545, 570,744], inplace = True)
In [136]:
matches.info()
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]:
In [139]:
deliveries.info()
In [140]:
deliveries[deliveries["is_super_over"] != 0].match_id.nunique() # matches with super over
Out[140]:
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");
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]:
In [ ]:
In [ ]:
Comments
Post a Comment