-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer_stats.py
28 lines (26 loc) · 956 Bytes
/
player_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Author: Abhijit Jaiswal
#Work In Progress
import csv
import pandas as pd
df = pd.read_csv("innings1.csv" )
matches = df.match.unique()
players = {}
bowlers = {}
for i in matches:
ndf = pd.DataFrame(df[df['match'] == i])
ndf = ndf.rename(columns=lambda x:x.strip())
for x in ndf.batsman.unique():
if x not in players.keys():
players[x] = ndf[ndf['batsman'] == x]['runs_batsman'].sum()
else:
players[x] = players[x] + ndf[ndf['batsman'] == x]['runs_batsman'].sum()
for y in ndf[ndf.wicket_kind.notnull() & (ndf['wicket_kind'] != 'run out')].bowler.unique():
if y not in bowlers.keys():
bowlers[y] = 1
else:
bowlers[y] = bowlers[y] + len(ndf[ndf.wicket_kind.notnull() & (ndf['wicket_kind'] != 'run out') & (ndf['bowler'] == y)])
if y == "V Sehwag":
print ndf[ndf.wicket_kind.notnull() & (ndf['wicket_kind'] != 'run out') & (ndf['bowler'] == y)]
#print bowlers[y]
#print players
print bowlers