<jupyter_start><jupyter_text>Welcome to Data Analysis in PythonIn this tutorial, We will see how to get started with Data Analysis in Python. The **Python packages** that we use in this notebook are:* `numpy`* `pandas`* `matplotlib`* `seaborn`The **dataset** that we use in this notebook is **IPL (Indian Premier League) Dataset** posted on **Kaggle Datasets** sourced from **[cricsheet](http://cricsheet.org/)**.![MSD](https://s3.ap-southeast-1.amazonaws.com/images.deccanchronicle.com/dc-Cover-vk3o0lgt5njai0ql5hov9artq5-20170715144519.Medi.jpeg) **Data Science / Analytics** is all about finding valuable insights from the given dataset. Inshort, Finding answers that could help business. So, let us try to ask some questions reg. IPL.  Questions:* How many matches we've got in the dataset?* How many seasons we've got in the dataset?* Which Team had won by maximum runs?* Which Team had won by maximum wicket?* Which Team had won by closest Margin (minimum runs)?* Which Team had won by minimum wicket?* Which Season had most number of matches?* Which IPL Team is more successful? * Has Toss-winning helped in winning matches?  Loading required Python packages<jupyter_code>import numpy as np # numerical computing 
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt #visualization
import seaborn as sns #modern visualization
%matplotlib inline
sns.set_style("darkgrid")
plt.rcParams['figure.figsize'] = (14, 8)
file_path = 'C:\\Users\\SA31\\Downloads\\'
matches = pd.read_csv(file_path+'matches.csv')
matches.shape
matches.head()
matches.describe()
matches.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 636 entries, 0 to 635
Data columns (total 18 columns):
id                 636 non-null int64
season             636 non-null int64
city               629 non-null object
date               636 non-null object
team1              636 non-null object
team2              636 non-null object
toss_winner        636 non-null object
toss_decision      636 non-null object
result             636 non-null object
dl_applied         636 non-null int64
winner             633 non-null object
win_by_runs        636 non-null int64
win_by_wickets     636 non-null int64
player_of_match    633 non-null object
venue              636 non-null object
umpire1            635 non-null object
umpire2            635 non-null object
umpire3            0 non-null float64
dtypes: float64(1), int64(5), object(12)
memory usage: 89.5+ KB<jupyter_text>How many matches we've got in the dataset?<jupyter_code>#matches.shape[0]

matches['id'].max()<jupyter_output><empty_output><jupyter_text>How many seasons we've got in the dataset?<jupyter_code>matches['season'].unique()
len(matches['season'].unique())<jupyter_output><empty_output><jupyter_text>Which Team had won by maximum runs?<jupyter_code>matches.iloc[matches['win_by_runs'].idxmax()]<jupyter_output><empty_output><jupyter_text>Which Team had won by maximum wickets?<jupyter_code>matches.iloc[matches['win_by_wickets'].idxmax()]<jupyter_output><empty_output><jupyter_text>Which Team had won by (closest margin) minimum runs?<jupyter_code>matches.iloc[matches[matches['win_by_runs'].ge(1)].win_by_runs.idxmin()]<jupyter_output><empty_output><jupyter_text>Which Team had won by minimum wickets?<jupyter_code>matches.iloc[matches[matches['win_by_wickets'].ge(1)].win_by_wickets.idxmin()]<jupyter_output><empty_output><jupyter_text>Which season had most number of matches?<jupyter_code>sns.countplot(x='season', data=matches)
plt.show()<jupyter_output><empty_output><jupyter_text>The most successful IPL Team<jupyter_code>#sns.countplot(y='winner', data = matches)
#plt.show

data = matches.winner.value_counts()
sns.barplot(y = data.index, x = data, orient='h');<jupyter_output><empty_output><jupyter_text>Top player of the match Winners<jupyter_code>top_players = matches.player_of_match.value_counts()[:10]
#sns.barplot(x="day", y="total_bill", data=tips)
fig, ax = plt.subplots()
ax.set_ylim([0,20])
ax.set_ylabel("Count")
ax.set_title("Top player of the match Winners")
#top_players.plot.bar()
sns.barplot(x = top_players.index, y = top_players, orient='v'); #palette="Blues");
plt.show()<jupyter_output><empty_output><jupyter_text>Has Toss-winning helped in Match-winning? How many Toss winning teams have won the matches?<jupyter_code>ss = matches['toss_winner'] == matches['winner']

ss.groupby(ss).size()<jupyter_output><empty_output><jupyter_text>What's the percentage of it?<jupyter_code>#ss.groupby(ss).size() / ss.count()

#ss.groupby(ss).size() / ss.count() * 100

round(ss.groupby(ss).size() / ss.count() * 100,2)
#sns.countplot(matches['toss_winner'] == matches['winner'])
sns.countplot(ss);<jupyter_output><empty_output><jupyter_text>Team Performance<jupyter_code>matches[matches['win_by_runs']>0].groupby(['winner'])['win_by_runs'].apply(np.median).sort_values(ascending = False)
#sns.barplot(x="day", y="total_bill", data=tips)
fig, ax = plt.subplots()
#fig.figsize = [16,10]
#ax.set_ylim([0,20])
ax.set_title("Winning by Runs - Team Performance")
#top_players.plot.bar()
sns.boxplot(y = 'winner', x = 'win_by_runs', data=matches[matches['win_by_runs']>0], orient = 'h'); #palette="Blues");
plt.show()
matches[matches['win_by_wickets']>0].groupby(['winner'])['win_by_wickets'].apply(np.median).sort_values(ascending = False)
#sns.barplot(x="day", y="total_bill", data=tips)
fig, ax = plt.subplots()
#fig.figsize = [16,10]
#ax.set_ylim([0,20])
ax.set_title("Winning by Wickets - Team Performance")
#top_players.plot.bar()
sns.boxplot(y = 'winner', x = 'win_by_wickets', data=matches[matches['win_by_wickets']>0], orient = 'h'); #palette="Blues");
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13718979377839916, 'fraction_numerical': 0.026214610276127228, 'mean_word_length': 5.764775413711584, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '91046', 'license': 'MIT', 'n_tokens_mistral': 2115, 'n_tokens_neox': 1996, 'n_words': 461, 'path': 'data_analysis/Data Analysis in Python with IPL Dataset.ipynb', 'repo_name': 'amrrs/iq18_workshop', 'size': '5722'}