Skip to content

Instantly share code, notes, and snippets.



Last active Feb 19, 2020
What would you like to do?
df_4 = batting_df.groupby('year').apply(lambda x: x.shape[0] / x[x['runs']==4].shape[0] ).reset_index(name='num_of_balls')
df_6 = batting_df.groupby('year').apply(lambda x: x.shape[0] / x[x['runs']==6].shape[0] ).reset_index(name='num_of_balls')
# A python dictionary
data = {"4":df_4['num_of_balls'].values,
index = df_4['year'].values
# Dictionary loaded into a DataFrame
dataFrame = pd.DataFrame(data=data, index=index);
# Draw a vertical bar chart
fig =, title="Avg no. of balls to score boundary (year wise)",figsize=(10,8)).get_figure()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.