<jupyter_start><jupyter_text>Out of 19 matches held between KXIP and RR , RR edge leads KXIP 10 is to 9. In the case with last three seasons, KXIP has got clear lead of victories over RR i.e 3 is to 1<jupyter_code>def statistics_for_lists(lst):
  print("Maximum Value Of List:")
  print(max(lst))
  print("Median of the List:")
  print(statistics.median(lst))
  print("Mean of the List:")
  print(statistics.mean(lst))
  print("75% of the Median is:")
  print(statistics.median_high(lst))
  print("Minimum Value of List:")
  print(min(lst))
deliveries = pd.read_csv("/content/sample_data/deliveries.csv")
deliveries.head()
dropToBeList = ['inning','is_super_over','bye_runs','legbye_runs','fielder']
deliveries.drop(dropToBeList, axis=1, inplace=True)
deliveries.replace(['Deccan Chargers','Delhi Daredevils'],['Sunrisers Hyderabad','Delhi Capitals'],inplace=True,regex=True)
deliveries['dismissal_kind'].fillna('Not Out',inplace=True)
deliveries.head()
ballbyball = deliveries[((deliveries.batting_team=="Kings XI Punjab") & (deliveries.bowling_team=="Rajasthan Royals")) | ((deliveries.batting_team=="Rajasthan Royals") & (deliveries.bowling_team=="Kings XI Punjab"))]
no_of_matches=list(set([i for i in ballbyball['match_id']]))
no_of_matches.sort()
print(len(no_of_matches))
#Q5
shami_stats = deliveries[deliveries.bowler=='<NAME>']
match_lst = list(set([i for i in shami_stats['match_id']]))
fst_wkt=[]
for i in match_lst:
  ball=0
  df=shami_stats[(shami_stats.match_id==i)]
  lst = [i for i in df['total_runs']]
  wide_lst = [i for i in df['wide_runs']]
  noball_lst = [i for i in df['noball_runs']]
  wkt_status = [i for i in df['dismissal_kind']]
  flag=0
  for j in range(len(lst)):
    if(wide_lst[j]>0 or noball_lst[j]>0):
      continue
    elif(wkt_status[j]!='Not Out' and wkt_status[j]!='run out' and wkt_status[j]!='stumped'):
      flag=1
      ball += 1
      break
    else:
      ball += 1
  if(flag==1):
    fst_wkt.append(ball)
  else:
    fst_wkt.append(0)
#print(fst_wkt)
wkt_taken_matches = [i for i in fst_wkt if i!=0]
print(len(wkt_taken_matches))
statistics_for_lists(wkt_taken_matches)<jupyter_output>30
Maximum Value Of List:
24
Median of the List:
15.0
Mean of the List:
14.566666666666666
75% of the Median is:
15
Minimum Value of List:
1<jupyter_text>Shami, in his entire IPL career, has taken a wicket 61% of times. In that possibility quota, he may possibly take his 1st wicket on 14 or 15th ball!<jupyter_code>#Q4
dot_balls = ballbyball[(ballbyball.total_runs==0) & (ballbyball.wide_runs==0) & (ballbyball.noball_runs==0)].groupby('match_id').total_runs.count()
dot_balls.describe()<jupyter_output><empty_output><jupyter_text>In all matches between KXIP and RR, the average number of dot balls expected is 85-97<jupyter_code>#Q3
all_batsman = list(set([i for i in ballbyball['batsman']]))
opp_batsman=[]
normalized_opp=[]
for i in all_batsman:
  reqVal=[]
  df = ballbyball[ballbyball.batsman==i]
  runs_scored = df.groupby('match_id').batsman_runs.sum().reset_index()
  balls_faced = df[(df.wide_runs==0) & (df.noball_runs==0)].groupby('match_id').ball.count().reset_index()
  balls_faced.rename(columns={'ball':'total_balls'},inplace=True)
  runs_4 = df[df.batsman_runs==4].groupby('match_id').ball.count().reset_index()
  runs_4.rename(columns={'ball':'no_of_4'},inplace=True)
  runs_1_2_3 = df[(df.batsman_runs==1) & (df.batsman_runs==2) & (df.batsman_runs==3)].groupby('match_id').ball.count().reset_index()
  runs_1_2_3.rename(columns={'ball':'no_of_123'},inplace=True)
  d1 = pd.merge(runs_scored,balls_faced,how='outer')
  d2 = pd.merge(runs_4,runs_1_2_3,how='outer')
  d = pd.merge(d1,d2,how='outer')
  d.fillna(0,inplace=True)
  l1=[i for i in d.batsman_runs]
  l2=[i for i in d.total_balls]
  l3=[i for i in d.no_of_4]
  l4=[i for i in d.no_of_123]
  for j in range(len(l1)):
    val = (l1[j]/l2[j])+l3[j]-l4[j]
    reqVal.append(val)
  opp_batsman.append(statistics.median(reqVal))
for i in range(len(all_batsman)):
  normalized_opp.append(round((opp_batsman[i]-min(opp_batsman))/(max(opp_batsman)-min(opp_batsman)),2))
for i,j in zip(all_batsman,normalized_opp):
  print(i+" "+str(j))
all_bowlers = list(set([i for i in ballbyball['bowler']]))
opp_bowler=[]
normalized_opp=[]
for i in all_bowlers:
  reqVal=[]
  df = ballbyball[ballbyball.bowler==i]
  boundaries_given = df[(df.total_runs==4) | (df.total_runs==5)].groupby('match_id').batsman_runs.sum().reset_index()
  balls_to_4 = df[(df.total_runs==4) | (df.total_runs==5)].groupby('match_id').ball.count().reset_index()
  balls_to_4.rename(columns={'ball':'no_of_4s'},inplace=True)
  total_balls_bowled = df[(df.wide_runs==0) | (df.noball_runs==0)].groupby('match_id').ball.count().reset_index()
  d1 = pd.merge(boundaries_given,balls_to_4,how='outer')
  d = pd.merge(d1,total_balls_bowled,how='outer')
  d.fillna(0,inplace=True)
  l1=[j for j in d['batsman_runs']]
  l2=[j for j in d['no_of_4s']]
  l3=[j for j in d['ball']]
  for j in range(len(l1)):
    try:
      val = (l1[j]/l2[j])/l3[j]
      reqVal.append(round(val,2))
    except:
      reqVal.append(0)
  opp_bowler.append(statistics.median(reqVal))
for i in range(len(all_bowlers)):
  normalized_opp.append(round((opp_bowler[i]-min(opp_bowler))/(max(opp_bowler)-min(opp_bowler)),2))
for i,j in zip(all_bowlers, normalized_opp):
  print(i+" "+str(j))
all_batsman = list(set([i for i in ballbyball['batsman']]))
all_ratios=[]
for i in all_batsman:
  ratios=[]
  df = ballbyball[ballbyball.batsman==i]
  runs_got = df.groupby('match_id').batsman_runs.sum()
  balls_played = df[(df.wide_runs==0) | (df.noball_runs==0)].groupby('match_id').ball.count()
  l1=[j for j in runs_got]
  l2=[j for j in balls_played]
  for j in range(len(l1)):
    if(l2[j]>10): 
      val = round((l1[j]/l2[j]),2)
      ratios.append(val)
    else:
      ratios.append(0)
  all_ratios.append(round(statistics.median(ratios)*100,2))
for i,j in zip(all_batsman,all_ratios):
  if j==0:
    continue
  else:
    print(i)
    print(j)
    print()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16824762855716424, 'fraction_numerical': 0.024629722083541354, 'mean_word_length': 5.829545454545454, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '389161', 'license': 'MIT', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2496, 'n_words': 445, 'path': 'archive/kxip_vs_rr.ipynb', 'repo_name': 'kh-2000/widhya-datascience-competition', 'size': '6017'}