<jupyter_start><jupyter_text>--- **TASK 5 - EXPLORATORY DATA ANALYSIS - SPORTS (INDIAN PREMIER LEAGUE)** **AUTHOR - <NAME>** **INTERN@THE SPARKS FOUNDATION**---  **IMPORTING LIBRARY AND LOAD DATASET**---<jupyter_code>import numpy as np 
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt 
from google.colab import files
uploaded = files.upload()
import io
sample_match = pd.read_csv(io.BytesIO(uploaded['matches.csv']))
sample_del = pd.read_csv(io.BytesIO(uploaded['deliveries.csv']))
sample_match = sample_match.drop(columns=["umpire3"],axis=1)

sample_match.head(2)
sample_del.head(2)<jupyter_output><empty_output><jupyter_text>--- **EXPLORATORY DATA ANALYSIS**---<jupyter_code>print(sample_match.info())
print(sample_del.info())<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 756 entries, 0 to 755
Data columns (total 17 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
dtypes: int64(5), object(12)
memory usag[...]<jupyter_text>--- **SEASON ANALYSIS** ---<jupyter_code>plt.figure(figsize = (18,6))
sns.countplot(x='venue', data=sample_match,palette="rocket", order = sample_match['venue'].value_counts().index)
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
sns.countplot('season',data=sample_match,palette="mako",order = sample_match['season'].value_counts().index)
plt.title("SEASONS WITH HEIGHEST NUMBER OF MATCHES")
plt.xlabel("SEASON")
plt.ylabel("FREQUENCY OF MATCHES")
plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/_decorators.py:43: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  FutureWarning<jupyter_text>**OBSERVATION FROM SEASON ANALYSIS***   Stadium Eden Garcen is the most chosen stadium for matches and ACA-VDCA Stadium is the least chosen one.*   The season 2013 has got most number of matches followed by 2012 and 2011 and 2009 has got the least number of matches. --- **TEAM ANALYSIS**---<jupyter_code>team_match = pd.melt(sample_match, id_vars=['id','season'], value_vars=['team1', 'team2'])
plt.figure(figsize = (18,6))
sns.countplot(x='value', data=team_match, palette="flare", order = team_match['value'].value_counts().index)
plt.title("TEAMS WITH HEIGHEST NUMBER OF MATCHES PLAYED")
plt.xlabel("TEAM")
plt.ylabel("FREQUENCY OF MATCHES")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
sns.countplot(x='winner',data=sample_match, palette='crest', order = sample_match['winner'].value_counts().index)
plt.title("TEAMS WITH HEIGHEST WINS")
plt.xticks(rotation=90)
plt.xlabel("TEAMS")
plt.ylabel("NUMBER OF WINS")
plt.show()
overall_win=sample_match.drop_duplicates(subset=['season'], keep='last')
plt.figure(figsize = (18,6))
sns.countplot(x='winner',data=overall_win, palette='magma', order = overall_win['winner'].value_counts().index)
plt.title("TEAMS WITH OVERALL WINS")
plt.xticks(rotation=90)
plt.xlabel("TEAMS")
plt.ylabel("NUMBER OF WINS")
plt.show()<jupyter_output><empty_output><jupyter_text>**OBSERVATION FROM TEAM ANALYSIS***   Team Mumbai Indians is the team with most number of maches played followed by Royal Challengers Bangalore. The teams like Rising Pune Supergiants, Kochi Tuskers Kerala played least number of matches.*   Team Mumba Indians has won most matches followed by Chennai Super Kings. The teams Rising Pune Supergiants, Kochi Tuskers Kerala has won least number of matches. Still, these teams are not bad when compared to the number of matches they have played.*   When analysed as overall win in a season, Mumbai Indians rule the leaderboard by winning four season followed by Chennai Super Kings who have won three seasons --- **TOSS ANALYSIS**---<jupyter_code>sns.countplot(x=sample_match["toss_decision"], palette="icefire")
plt.figure(figsize=(18,6))
sns.countplot(x='toss_winner', hue='toss_decision', data=sample_match, palette="viridis")
plt.xlabel("TEAMS")
plt.ylabel("FREQUENCY OF OPTING BAT/BALL")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize=(18,6))
sns.countplot(x='season', hue='toss_decision', data=sample_match, palette="viridis")
plt.xlabel("SEASON")
plt.ylabel("FREQUENCY OF OPTING BAT/BALL")
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>**OBSERVATION FROM TOSS ANALYSIS***   Overall probability of a toss winner opting for field is higher than opting for bat.*   Each team seems to have their startegy of choosing the toss decision. Teams Chennai Super Kings, Deccan Chargers and Pune warriors have chosen bat first more number of times than field first. Other all teams has chosen field first more times.*   From Season 2014, we see a trend transition of prefering field first same as in 2008 and 2011. In 2012, bat and field where chosen equally. --- **HEIGHEST CHOSEN UMPIRES**---<jupyter_code>sample_umpire = pd.melt(sample_match, id_vars=['id'], value_vars=['umpire1', 'umpire2'])
sample_umpire['value'].unique()
plt.figure(figsize=(18,6))
sns.countplot(x='value', data=sample_umpire, palette="icefire", order = sample_umpire['value'].value_counts().index)
plt.xlabel("UMPIRE")
plt.ylabel("FREQUENCY OF CHOOSING UMPIRE")
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>--- **PLAYER OF MATCH**---<jupyter_code>plt.figure(figsize = (18,6))
plt.ylim([0,30])
plt.title("PLAYER OF THE MATCH")
sns.barplot(x = sample_match["player_of_match"].value_counts()[:30].index, y = sample_match["player_of_match"].value_counts()[:30], palette="viridis")
plt.ylabel("NUMBER OF TIMES A PLAYER IS PLAYER OF THE MATCH")
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>**OBSERVATION FROM PLAYER OF THE MATCH***   <NAME> is ruling the leaderboard by getting player of the match slightly heigher than <NAME>.*   It is also convincing to see that <NAME> and <NAME> were the player of the match in few matches. --- **BATSMAN ANALYSIS**---<jupyter_code>plt.figure(figsize = (18,6))
high_run = sample_del.groupby('batsman')['batsman_runs'].agg('sum').reset_index().sort_values(by='batsman_runs', ascending=False).reset_index(drop=True)
plt.title("BATSMAN WITH HEIGHEST NUMBER OF RUNS")
sns.barplot(x = high_run["batsman"].iloc[:20], y = high_run["batsman_runs"].iloc[:20], data= high_run, palette="cubehelix")
plt.xlabel("BATSMAN")
plt.ylabel("NUMBER OF RUNS")
plt.xticks(rotation=90)
plt.show()
least_run=high_run.tail(20)
plt.figure(figsize = (18,6))
plt.title("BATSMAN WITH LEAST NUMBER OF RUNS")
sns.barplot(x = least_run["batsman"], y = least_run["batsman_runs"], data= least_run, palette="autumn")
plt.ylabel("NUMBER OF RUNS")
plt.xlabel("BATSMAN")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
high_bound = sample_del.groupby('batsman')['batsman_runs'].agg(lambda x: (x==4).sum()).reset_index().sort_values(by='batsman_runs', ascending=False).reset_index(drop=True)
plt.title("BATSMAN WITH HEIGHEST NUMBER OF BOUNDARIES")
sns.barplot(x = high_bound["batsman"].iloc[:20], y = high_bound["batsman_runs"].iloc[:20], data= high_bound, palette="autumn")
plt.xlabel("BATSMAN")
plt.ylabel("NUMBER OF BOUNDARIES")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
high_six = sample_del.groupby('batsman')['batsman_runs'].agg(lambda x: (x==6).sum()).reset_index().sort_values(by='batsman_runs', ascending=False).reset_index(drop=True)
plt.title("BATSMAN WITH HEIGHEST NUMBER OF SIX")
sns.barplot(x = high_six["batsman"].iloc[:20], y = high_six["batsman_runs"].iloc[:20], data= high_six, palette="coolwarm")
plt.xlabel("BATSMAN")
plt.ylabel("NUMBER OF SIX")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
high_dot = sample_del.groupby('batsman')['batsman_runs'].agg(lambda x: (x==0).sum()).reset_index().sort_values(by='batsman_runs', ascending=False).reset_index(drop=True)
plt.title("BATSMAN WHO PLAYED HEIGHEST NUMBER OF DOT BALLS")
sns.barplot(x = high_dot["batsman"].iloc[:20], y = high_dot["batsman_runs"].iloc[:20], data= high_dot, palette="inferno")
plt.xlabel("BATSMAN")
plt.ylabel("NUMBER OF DOT BALLS")
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>**OBSERVATION FROM BATSMAN ANALYSIS***   <NAME> followed by <NAME> has secured most number of runs and nearly 16 batsmen have not scored any run for their team.*   <NAME>, <NAME>, <NAME> and <NAME> secure the leaderboard in most number of boundaries.*   <NAME> has took his unbeatable first place in hitting most number of six. <NAME> and <NAME> has scored least number of six among the top 20.*   <NAME> has batted heighest number of Dot Balls. --- **DISMISSAL TYPE ANALYSIS**---<jupyter_code>plt.figure(figsize = (18,6))
sns.countplot(x=sample_del['dismissal_kind'], palette="Wistia", order = sample_del['dismissal_kind'].value_counts().index)
plt.xlabel("DISMISSAL KIND")
plt.ylabel("FREQUENCY OF DISMISSAL")
plt.title("MOST DISMISSAL TYPE")
plt.xticks(rotation='vertical')
plt.show()<jupyter_output><empty_output><jupyter_text>**Caught is the most common dismissal type in IPL followed by bowled** --- **BOWLERS ANALYSIS**---<jupyter_code>plt.figure(figsize = (18,6))
high_bowl = sample_del.groupby('bowler')['ball'].agg('count').reset_index().sort_values(by='ball', ascending=False).reset_index(drop=True)
plt.title("BOWLERS WHO BOWLED HEIGHEST NUMBER OF BALLS")
sns.barplot(x = high_bowl["bowler"].iloc[:20], y= high_bowl["ball"].iloc[:20], data= high_bowl, palette="copper")
plt.xlabel("BOWLERS")
plt.ylabel("NUMBER OF BALLS BOWLED")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
high_bowl_extra = sample_del.groupby('bowler')['extra_runs'].agg(lambda x: (x>0).sum()).reset_index().sort_values(by='extra_runs', ascending=False).reset_index(drop=True)
plt.title("BOWLERS WHO BOWLED HEIGHEST NUMBER OF EXTRA BALLS")
sns.barplot(x = high_bowl_extra["bowler"].iloc[:20], y= high_bowl_extra["extra_runs"].iloc[:20], data= high_bowl_extra, palette="gist_earth")
plt.xlabel("BOWLERS")
plt.ylabel("NUMBER OF EXTRA BALLS BOWLED")
plt.xticks(rotation=90)
plt.show()
plt.figure(figsize = (18,6))
high_bowl_dot = sample_del.groupby('bowler')['total_runs'].agg(lambda x: (x==0).sum()).reset_index().sort_values(by='total_runs', ascending=False).reset_index(drop=True)
plt.title("BOWLERS WHO BOWLED HEIGHEST NUMBER OF DOT BALLS")
sns.barplot(x = high_bowl_dot["bowler"].iloc[:20], y= high_bowl_dot["total_runs"].iloc[:20], data= high_bowl_dot, palette="gist_rainbow")
plt.xlabel("BOWLERS")
plt.ylabel("NUMBER OF DOT BALLS BOWLED")
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14779102384291726, 'fraction_numerical': 0.024807152875175317, 'mean_word_length': 5.811343283582089, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '215303', 'license': 'Apache-2.0', 'n_tokens_mistral': 4446, 'n_tokens_neox': 4047, 'n_words': 944, 'path': 'TASK_5.ipynb', 'repo_name': 'student-entrepreneur/TSP-GRIP-Data-Science-TASK-5-', 'size': '11449'}