Created
May 30, 2021 15:28
-
-
Save Lakshmi-1212/90b68ac84fbfff861bdda238333b9fef to your computer and use it in GitHub Desktop.
Bowling Statistics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Group details on bowler | |
bowlgroup = balldf.groupby(['bowler']) | |
# Create a bowling dataframe (bowldf) with a summary statistics for each batsman | |
bowldf = pd.DataFrame(bowlgroup['ball'].count()).rename(columns={'ball':'balls_bowled'}) | |
# Get no. of wickets taken by each bowler | |
bwl_wkts = balldf[balldf['dismissal_kind'].isin(['caught','bowled', 'lbw','stumped', 'caught and bowled', 'hit wicket'])] | |
bowldf['wickets'] = bwl_wkts.groupby(['bowler'])['ball'].count() | |
bowldf['wickets'].fillna(0,inplace=True) | |
# Calculate the total no. of overs bowled | |
overs = pd.DataFrame(balldf.groupby(['bowler','id'])['over'].nunique()) | |
bowldf['overs'] = overs.groupby(['bowler'])['over'].sum() | |
# Calculate the runs conceded | |
bowldf['runs_conceded'] = balldf.groupby('bowler')['batsman_runs'].sum() | |
bowldf['runs_conceded'] = bowldf['runs_conceded'].fillna(0) | |
# Add the runs conceded through wide and noball | |
bowldf['runs_conceded'] = bowldf['runs_conceded'].add(balldf[balldf['extras_type'].isin(['wides','noballs'])].groupby('bowler')['extra_runs'].sum(),fill_value=0) | |
# Note - roughly apprx to overs. Should be runs_conceded/overs.balls | |
bowldf['bowl_econ'] = round(bowldf['runs_conceded']/bowldf['overs'],2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment