<jupyter_start><jupyter_text>Match Analysis<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline<jupyter_output><empty_output><jupyter_text>Data Cleaning and Exploration<jupyter_code>matches = pd.read_csv("matches.csv" , index_col = "id")
matches = matches.iloc[:,:-3]
matches.shape
matches.winner.unique()<jupyter_output><empty_output><jupyter_text>Taking in consideration only KKR VS RCB matches<jupyter_code>RK =matches[np.logical_or(np.logical_and(matches['team1']=='Kolkata Knight Riders',matches['team2']=='Royal Challengers Bangalore'),
                            np.logical_and(matches['team2']=='Kolkata Knight Riders',matches['team1']=='Royal Challengers Bangalore'))]
RK.shape
RK.isnull().sum()
RK.describe().iloc[:,2:].T<jupyter_output><empty_output><jupyter_text>HEAD TO HEAD<jupyter_code>RK.groupby("winner")["winner"].count()
sns.countplot(RK["winner"])
plt.text(-0.07,12.5,str(RK['winner'].value_counts()['Kolkata Knight Riders']),size=20,color='white')
plt.text(0.95,8.5,str(RK['winner'].value_counts()['Royal Challengers Bangalore']),size=20,color='white')
plt.xlabel('Winner',fontsize=15)
plt.ylabel('No. of Matches',fontsize=15)
plt.title('KKR VS RCB-head to head',fontsize = 20)
Season_wise_Match_Winner = pd.DataFrame(RK.groupby(["season","winner"])["winner"].count())

Season_wise_Match_Winner.columns = ["winner count"]

print("Season wise winner of matches between KKR VS RCB :")
Season_wise_Match_Winner<jupyter_output>Season wise winner of matches between KKR VS RCB :<jupyter_text>Winning Percentage<jupyter_code>Winning_Percentage = RK['winner'].value_counts()/len(RK['winner'])
print("KKR winning percentage against RCB(overall) : {}%".format(int(round(Winning_Percentage[0]*100))))
print("RCB winning percentage against KKR(overall) : {}%".format(int(round(Winning_Percentage[1]*100))))
def performance( team_name , given_df ):
    for value in given_df.groupby('winner'):
        if value[0] == team_name:

            total_win_by_runs = sum(list(value[1]['win_by_runs']))
            total_win_by_wickets = sum(list(value[1]['win_by_wickets']))
            
            if 0 in list(value[1]['win_by_runs'].value_counts().index):
                x = value[1]['win_by_runs'].value_counts()[0]
            else:
                x = 0
                
            if 0 in list(value[1]['win_by_wickets'].value_counts().index):
                y = value[1]['win_by_wickets'].value_counts()[0]
            else:
                y = 0
                
            number_of_times_given_team_win_while_defending = (len(value[1]) - x )
            number_of_times_given_team_win_while_chasing = (len(value[1]) - y )
            
            average_runs_by_which_a_given_team_wins_while_defending = total_win_by_runs / number_of_times_given_team_win_while_defending
            average_wickets_by_which_a_given_team_wins_while_chasing = total_win_by_wickets / number_of_times_given_team_win_while_chasing
            
            print('Number of times given team win while defending :' , number_of_times_given_team_win_while_defending ) 
            print('Number of times given team win while chasing   :' , number_of_times_given_team_win_while_chasing )
            print()
            print('Average runs by which a given team wins while defending  : ' ,round(average_runs_by_which_a_given_team_wins_while_defending))
            print('Average wickets by which a given team wins while chasing : ' ,round(average_wickets_by_which_a_given_team_wins_while_chasing))
performance("Kolkata Knight Riders",RK)
performance('Royal Challengers Bangalore',RK)<jupyter_output>Number of times given team win while defending : 1
Number of times given team win while chasing   : 9

Average runs by which a given team wins while defending  :  10.0
Average wickets by which a given team wins while chasing :  6.0<jupyter_text>Above Performance analysis give a breif overview of dominance of KKR over RCB. But we can also see a clear chasing dominance of RCB when they win matches  Toss Analysis<jupyter_code>Toss_Decision = pd.DataFrame(RK.groupby(['toss_winner',"toss_decision"])["toss_decision"].count())

print ("Toss winner decision :")
Toss_Decision
sns.set(style='whitegrid')
plt.figure(figsize = (18,8))
sns.countplot(RK['toss_winner'],palette='Set2',hue=RK['toss_decision'])
plt.title('Toss decision statistics for both team',fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlabel('Toss winner',fontsize=15)
plt.ylabel('Count',fontsize=15)
plt.legend(loc='best',fontsize=15)
plt.show()
Toss_Decision_based_Winner = pd.DataFrame(RK.groupby(['toss_winner',"toss_decision","winner"])["winner"].count())

print(" No of times toss winning decision leading to match winning : ")
Toss_Decision_based_Winner
sns.set(style='whitegrid')
plt.figure(figsize = (18,9))
sns.countplot(RK['toss_winner'],hue=RK['winner'])
plt.title('Match Winner vs Toss Winner statistics for both team',fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlabel('Toss winner',fontsize=15)
plt.ylabel('Match Winner',fontsize=15)
plt.legend(loc="best",fontsize=15)<jupyter_output><empty_output><jupyter_text>Toss Decision based Analysis of both the teams seperately :<jupyter_code>KKR = RK[RK["toss_winner"]=="Kolkata Knight Riders"]
RCB = RK[RK["toss_winner"]=="Royal Challengers Bangalore"]
sns.set(style='whitegrid')
plt.figure(figsize = (18,9))
sns.countplot(KKR['toss_decision'],hue=KKR['winner'])
plt.title('Match Winner vs Toss Winner statistics for KKR',fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlabel('Toss decision of KKR',fontsize=15)
plt.ylabel('Match Winner',fontsize=15)
plt.legend(loc=1,fontsize=15)
sns.set(style='whitegrid')
plt.figure(figsize = (18,9))
sns.countplot(RCB['toss_decision'],hue=RCB['winner'])
plt.title('Match Winner vs Toss Winner statistics for RCB',fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlabel('Toss decision of RCB',fontsize=15)
plt.ylabel('Match Winner',fontsize=15)
plt.legend(loc=1,fontsize=15)
player_of_the_match = pd.DataFrame(RK.player_of_match.value_counts())

print("Man of the match :")

player_of_the_match<jupyter_output>Man of the match :<jupyter_text>Recent Year Performance Analysis<jupyter_code>cond1 = RK["season"] == 2017
cond2 = RK["season"] == 2018
cond3 = RK["season"] == 2019
final = RK[cond1 | cond2 | cond3]
final
final.shape
player = pd.DataFrame(final.player_of_match.value_counts())

print("Man of the match :")
player
plt.figure(figsize = (10,6))
sns.countplot(final['winner'])
plt.title('Match won in recent years',fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
plt.xlabel('Team',fontsize=15)
plt.ylabel('Win Count',fontsize=15)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13604240282685512, 'fraction_numerical': 0.022232037691401647, 'mean_word_length': 5.854692230070635, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '44144', 'license': 'MIT', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2384, 'n_words': 430, 'path': 'KKR VS RCB/Match Analysis KKR VS RCB.ipynb', 'repo_name': 'tacklesta/WPL', 'size': '6792'}