Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Last active February 19, 2020 05:20
Show Gist options
  • Save aravindpai/a4b54472bd32b639dfcb5e205b259d24 to your computer and use it in GitHub Desktop.
Save aravindpai/a4b54472bd32b639dfcb5e205b259d24 to your computer and use it in GitHub Desktop.
pp=powerplay_batting_df.groupby('year').apply(lambda x: x.shape[0] / x[x['runs']==4.shape[0] ).reset_index(name='no_of_balls')
middle=middle_batting_df.groupby('year').apply(lambda x: x.shape[0] / x[x['runs']==4].shape[0] ).reset_index(name='no_of_balls')
last=last_batting_df.groupby('year').apply(lambda x: x.shape[0] / x[x['runs']==4].shape[0] ).reset_index(name='no_of_balls')
# A python dictionary
data = {"Powerplay":pp['no_of_balls'].values,
"Middle overs":middle['no_of_balls'].values,
"Last 5 overs":last['no_of_balls'].values
};
index = last['year'].values
# Dictionary loaded into a DataFrame
dataFrame = pd.DataFrame(data=data, index=index);
# Draw a vertical bar chart
axes = dataFrame.plot.bar(rot=0, title="Avg no. of balls to hit 4")
fig=axes.get_figure()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment