text_plain_output_1.png image_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import numpy as np
import pandas as pd
import seaborn as sns
Deliveries_Data = pd.read_csv('../input/deliveries_expanded.csv')
Matches_Data = pd.read_csv('../input/matches_expanded.csv')

Deliveries_Data.head(2)

Deliveries_Powerplay = Deliveries_Data.loc[Deliveries_Data["over"] < 7]
#Delivery_team = Deliveries_Powerplay[Deliveries_Powerplay["batting_team"] == "Sunrisers Hyderabad"]
Deliveries_team_analysed = Deliveries_Powerplay.groupby(['batting_team','over'])['total_runs'].sum().unstack().plot(kind="bar",figsize = (15,5))
Deliveries_team_analysed.get_legend().set_bbox_to_anchor((0.18,1))
#Deliveries_team_analysed
#.sort_values(by ="total_runs", ascending = False)

Contribution_data = Deliveries_Data.groupby(['batting_team', 'over_type'])['total_runs'].sum().unstack()
Contribution_data['%Runs_Powerplay'] = Contribution_data['Powerplay_Over'] / (Contribution_data['Death_Over'] + Contribution_data['Middle_Over'] + Contribution_data['Powerplay_Over']) * 100
Contribution_data['%Runs_MiddleOvers'] = Contribution_data['Middle_Over'] / (Contribution_data['Death_Over'] + Contribution_data['Middle_Over'] + Contribution_data['Powerplay_Over']) * 100
Contribution_data['%Runs_DeathOvers'] = Contribution_data['Death_Over'] / (Contribution_data['Death_Over'] + Contribution_data['Middle_Over'] + Contribution_data['Powerplay_Over']) * 100
Contribution_data
Plot = Contribution_data[['%Runs_Powerplay', '%Runs_MiddleOvers', '%Runs_DeathOvers']].sort_values(by='%Runs_DeathOvers', ascending=False).plot(kind='bar', stacked=True, figsize=(15, 5))

Deliveries_Data.columns

Deliveries_extras_analysed = Deliveries_Data[['batting_team', 'bowling_team', 'over_type', 'bowler', 'batsman', 'wide_runs', 'bye_runs', 'legbye_runs', 'noball_runs', 'penalty_runs', 'batsman_runs', 'extra_runs', 'total_runs']]

Extra_Columns = ['batting_team', 'bowling_team', 'over_type', 'bowler', 'batsman', 'wide_runs', 'bye_runs', 'legbye_runs', 'noball_runs', 'penalty_runs', 'batsman_runs', 'extra_runs', 'total_runs']
Extra_Columns
Deliveries_extras_analysed['Total_Extras'] = Deliveries_extras_analysed[Extra_Columns].sum(axis=1)
Deliveries_extras_analysed.head(2)
Extras_Over_type = Deliveries_extras_analysed.groupby(['bowling_team', 'over_type'])['extra_runs'].sum().unstack()
Extras_Runs = Deliveries_extras_analysed.groupby(['bowling_team', 'batting_team'])['extra_runs'].sum().unstack().fillna(0)
Extras_Over_type.plot(kind='bar', figsize=(15, 5)).get_legend().set_bbox_to_anchor((1, 1))