Jovian
⭐️
Sign In
In [1]:
!pip install jovian --upgrade --quiet
In [2]:
!pip install pandas --upgrade
Requirement already up-to-date: pandas in /srv/conda/envs/notebook/lib/python3.7/site-packages (1.1.2) Requirement already satisfied, skipping upgrade: python-dateutil>=2.7.3 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from pandas) (2.8.1) Requirement already satisfied, skipping upgrade: numpy>=1.15.4 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from pandas) (1.19.2) Requirement already satisfied, skipping upgrade: pytz>=2017.2 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from pandas) (2020.1) Requirement already satisfied, skipping upgrade: six>=1.5 in /srv/conda/envs/notebook/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
In [12]:
!pip install matplotlib seaborn --upgrade --quiet
In [83]:
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

sns.set_style('darkgrid')
matplotlib.rcParams['font.size'] = 14
matplotlib.rcParams['figure.figsize'] = (9, 5)
matplotlib.rcParams['figure.facecolor'] = '#00000000'

In [84]:
import jovian
In [3]:
matches_raw_df = pd.read_csv('matches.csv')
In [4]:
matches_raw_df
Out[4]:
In [6]:
matches_raw_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 756 entries, 0 to 755 Data columns (total 18 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 756 non-null int64 1 season 756 non-null int64 2 city 749 non-null object 3 date 756 non-null object 4 team1 756 non-null object 5 team2 756 non-null object 6 toss_winner 756 non-null object 7 toss_decision 756 non-null object 8 result 756 non-null object 9 dl_applied 756 non-null int64 10 winner 752 non-null object 11 win_by_runs 756 non-null int64 12 win_by_wickets 756 non-null int64 13 player_of_match 752 non-null object 14 venue 756 non-null object 15 umpire1 754 non-null object 16 umpire2 754 non-null object 17 umpire3 119 non-null object dtypes: int64(5), object(13) memory usage: 106.4+ KB
In [7]:
import jovian
In [9]:
jovian.commit(files = ['matches.csv'])
[jovian] Attempting to save notebook.. [jovian] Updating notebook "srijansrj5901/ipl-matches-data-analysis" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Uploading additional files... [jovian] Committed successfully! https://jovian.ml/srijansrj5901/ipl-matches-data-analysis
In [67]:
matches_per_season = matches_raw_df.groupby('season').season.count()
In [68]:
matches_per_season
Out[68]:
season
2008    58
2009    57
2010    60
2011    73
2012    74
2013    76
2014    60
2015    59
2016    60
2017    59
2018    60
2019    60
Name: season, dtype: int64
In [94]:
plt.figure(figsize=(12,6))
plt.xticks(rotation=75)
plt.title('Matches Per Season')
sns.barplot(matches_per_season.index, matches_per_season)

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-94-d9fd6cb1c97c> in <module> 2 plt.xticks(rotation=75) 3 plt.title('Matches Per Season') ----> 4 sns.set_xlabel('Seasons') 5 sns.set_ylabel('No. Of Matches') 6 sns.barplot(matches_per_season.index, matches_per_season); AttributeError: module 'seaborn' has no attribute 'set_xlabel'
In [72]:
toss_decision_percentage = matches_raw_df.groupby('season').toss_decision.value_counts() / matches_per_season * 100
In [73]:
toss_decision_percentage
Out[73]:
season  toss_decision
2008    field            55.172414
        bat              44.827586
2009    bat              61.403509
        field            38.596491
2010    bat              65.000000
        field            35.000000
2011    field            65.753425
        bat              34.246575
2012    bat              50.000000
        field            50.000000
2013    bat              59.210526
        field            40.789474
2014    field            68.333333
        bat              31.666667
2015    field            57.627119
        bat              42.372881
2016    field            81.666667
        bat              18.333333
2017    field            81.355932
        bat              18.644068
2018    field            83.333333
        bat              16.666667
2019    field            83.333333
        bat              16.666667
dtype: float64
In [81]:
plt.hist(['toss_decision_percentage.index', 'toss_decision_percentage.toss_decision'])
Out[81]:
(array([1., 0., 0., 0., 0., 0., 0., 0., 0., 1.]),
 array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ]),
 <BarContainer object of 10 artists>)
In [10]:
matches_raw_df[matches_raw_df.season >= 2019].toss_winner.value_counts() / (matches_raw_df[matches_raw_df.season >= 2019].team2.value_counts() + matches_raw_df[matches_raw_df.season >= 2019].team1.value_counts()) * 100

Out[10]:
Chennai Super Kings            70.588235
Delhi Capitals                 62.500000
Kings XI Punjab                42.857143
Kolkata Knight Riders          35.714286
Mumbai Indians                 50.000000
Rajasthan Royals               78.571429
Royal Challengers Bangalore    28.571429
Sunrisers Hyderabad            26.666667
dtype: float64
In [11]:
(matches_raw_df.team2.value_counts() + matches_raw_df.team1.value_counts())

Out[11]:
Chennai Super Kings            164
Deccan Chargers                 75
Delhi Capitals                  16
Delhi Daredevils               161
Gujarat Lions                   30
Kings XI Punjab                176
Kochi Tuskers Kerala            14
Kolkata Knight Riders          178
Mumbai Indians                 187
Pune Warriors                   46
Rajasthan Royals               147
Rising Pune Supergiant          16
Rising Pune Supergiants         14
Royal Challengers Bangalore    180
Sunrisers Hyderabad            108
dtype: int64
In [12]:
matches_raw_df.winner.value_counts() / (matches_raw_df.team2.value_counts() + matches_raw_df.team1.value_counts()) * 100
Out[12]:
Chennai Super Kings            60.975610
Deccan Chargers                38.666667
Delhi Capitals                 62.500000
Delhi Daredevils               41.614907
Gujarat Lions                  43.333333
Kings XI Punjab                46.590909
Kochi Tuskers Kerala           42.857143
Kolkata Knight Riders          51.685393
Mumbai Indians                 58.288770
Pune Warriors                  26.086957
Rajasthan Royals               51.020408
Rising Pune Supergiant         62.500000
Rising Pune Supergiants        35.714286
Royal Challengers Bangalore    46.666667
Sunrisers Hyderabad            53.703704
dtype: float64
In [13]:
matches_raw_df.sort_values('win_by_runs', ascending = False).head(20)
Out[13]:
In [14]:
matches_raw_df.sort_values('win_by_wickets', ascending = False).head(20)
Out[14]:
In [8]:
matches_raw_df.umpire1.value_counts() + matches_raw_df.umpire2.value_counts().max()
Out[8]:
HDPK Dharmasena    130
Asad Rauf          108
S Ravi             106
AK Chaudhary       100
Aleem Dar           95
                  ... 
Sundaram Ravi       58
A Nanda Kishore     58
Nanda Kishore       58
SL Shastri          58
SJA Taufel          58
Name: umpire1, Length: 61, dtype: int64
In [25]:
matches_raw_df[(matches_raw_df.toss_decision == 'field') & (matches_raw_df.toss_winner == matches_raw_df.winner)].winner.value_counts()
Out[25]:
Kolkata Knight Riders          38
Royal Challengers Bangalore    32
Mumbai Indians                 31
Kings XI Punjab                29
Rajasthan Royals               27
Chennai Super Kings            27
Delhi Daredevils               24
Sunrisers Hyderabad            15
Gujarat Lions                  10
Deccan Chargers                 8
Delhi Capitals                  6
Rising Pune Supergiant          5
Kochi Tuskers Kerala            4
Rising Pune Supergiants         3
Name: winner, dtype: int64
In [26]:
matches_raw_df[(matches_raw_df.toss_decision == 'bat') & (matches_raw_df.toss_winner != matches_raw_df.winner)].winner.value_counts()
Out[26]:
Chennai Super Kings            22
Kolkata Knight Riders          20
Mumbai Indians                 20
Rajasthan Royals               19
Delhi Daredevils               18
Royal Challengers Bangalore    17
Kings XI Punjab                15
Sunrisers Hyderabad            13
Pune Warriors                   6
Deccan Chargers                 3
Rising Pune Supergiants         2
Gujarat Lions                   2
Delhi Capitals                  1
Name: winner, dtype: int64
In [29]:
matches_raw_df[(matches_raw_df.toss_decision == 'bat') & (matches_raw_df.toss_winner == matches_raw_df.winner)].winner.value_counts()
Out[29]:
Chennai Super Kings            30
Mumbai Indians                 25
Kolkata Knight Riders          15
Rajasthan Royals               15
Deccan Chargers                11
Delhi Daredevils               11
Royal Challengers Bangalore     9
Sunrisers Hyderabad             8
Kings XI Punjab                 6
Pune Warriors                   3
Delhi Capitals                  1
Name: winner, dtype: int64
In [30]:
matches_raw_df[(matches_raw_df.toss_decision == 'field') & (matches_raw_df.toss_winner != matches_raw_df.winner)].winner.value_counts()
Out[30]:
Mumbai Indians                 33
Kings XI Punjab                32
Royal Challengers Bangalore    26
Sunrisers Hyderabad            22
Chennai Super Kings            21
Kolkata Knight Riders          19
Delhi Daredevils               14
Rajasthan Royals               14
Deccan Chargers                 7
Rising Pune Supergiant          5
Pune Warriors                   3
Kochi Tuskers Kerala            2
Delhi Capitals                  2
Gujarat Lions                   1
Name: winner, dtype: int64
In [ ]:
 
In [ ]:
 
In [79]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "srijansrj5901/ipl-matches-data-analysis" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/srijansrj5901/ipl-matches-data-analysis
In [80]:
jovian.commit(files = ['matches.csv'])
[jovian] Attempting to save notebook.. [jovian] Updating notebook "srijansrj5901/ipl-matches-data-analysis" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Uploading additional files... [jovian] Committed successfully! https://jovian.ml/srijansrj5901/ipl-matches-data-analysis
In [ ]: