Created
May 30, 2021 15:27
-
-
Save Lakshmi-1212/7d0d7a981c9f294a0a6997982e92286a to your computer and use it in GitHub Desktop.
Batsman 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 batsmen | |
batgroup = balldf.groupby(['batsman']) | |
# Create a batting dataframe with a summary statistics for each batsman | |
batdf = pd.DataFrame(batgroup['ball'].count()).rename(columns={'ball':'balls_faced'}) | |
batdf['innings'] = batgroup['id'].nunique() | |
batdf['runs'] = batgroup['batsman_runs'].sum() | |
batdf['4s'] = balldf[balldf['batsman_runs'] == 4].groupby('batsman')['batsman_runs'].count() | |
batdf['4s'].fillna(0,inplace=True) | |
batdf['6s'] = balldf[balldf['batsman_runs'] == 6].groupby('batsman')['batsman_runs'].count() | |
batdf['6s'].fillna(0,inplace=True) | |
# Batting average = total rus scored/no. of times batsman is been dismissed | |
# Approximated here to matches instead of no. of dismissals | |
batdf['bat_average'] = round(batdf['runs']/batdf['innings'],2) | |
# Strike Rate = (Runs Scored / Balls faced) * 100 | |
batdf['bat_strike'] = round(batdf['runs']/batdf['balls_faced']*100,2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment