text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

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')

Overall_Matches_State = pd.Series.to_frame(Matches_Data['State'].value_counts())
Overall_Matches_State['%Contribution'] = Overall_Matches_State['State'] / Overall_Matches_State['State'].sum() * 100

Overall_Matches_Zone = pd.Series.to_frame(Matches_Data['Zone'].value_counts())
Overall_Matches_Zone['%Contribution'] = Overall_Matches_Zone['Zone'] / Overall_Matches_Zone['Zone'].sum() * 100

import matplotlib.pyplot as plt
Matches_understood_by_year =  pd.Series.to_frame(Matches_Data.groupby('season')['Zone'].value_counts())
Plot_Zone = Matches_Data.groupby('season')['Zone'].value_counts().unstack().plot(kind="bar", figsize = (15,5))
print(Plot_Zone.get_legend().set_bbox_to_anchor((0.15,1)))

Matches_Data.groupby('city')['Winner_Zone_Type'].value_counts().unstack().dropna().plot(kind='bar', figsize=(15, 5))

Distinct_Team = Matches_Data['team1'].unique()
Total_Teams = len(Distinct_Team)
for i in range(Total_Teams):
    Team_Name = Distinct_Team[i]
    Matches_Data_Toss_Comparision = Matches_Data[['city', 'Zone', 'toss_winner', 'toss_decision', 'Toss_Win_Zone', 'winner', 'Winner_Zone']]
    Matches_Data_Toss_Comparision = Matches_Data_Toss_Comparision[Matches_Data_Toss_Comparision['toss_winner'] == Team_Name]
    Matches_Data_Toss_Comparision['Win_comparison'] = Matches_Data_Toss_Comparision.apply(lambda x: 'Win' if x['toss_winner'] == x['winner'] else 'Lost', axis=1)

Matches_Data_Toss_Comparision = Matches_Data[['city', 'Zone', 'toss_winner', 'toss_decision', 'Toss_Win_Zone', 'winner', 'Winner_Zone']]
Matches_Data_Toss_Comparision = Matches_Data_Toss_Comparision[Matches_Data_Toss_Comparision['toss_winner'] == 'Mumbai Indians']
Matches_Data_Toss_Comparision['Win_comparison'] = Matches_Data_Toss_Comparision.apply(lambda x: 'Win' if x['toss_winner'] == x['winner'] else 'Lost', axis=1)
print(Matches_Data_Toss_Comparision.groupby(['toss_decision', 'Zone'])['Win_comparison'].value_counts().unstack().plot(kind='bar', stacked=True, figsize=(15, 5)))