Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Last active February 19, 2020 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aravindpai/7ef71c20059ed0b7c3980a90de41bec0 to your computer and use it in GitHub Desktop.
Save aravindpai/7ef71c20059ed0b7c3980a90de41bec0 to your computer and use it in GitHub Desktop.
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,
"6":df_6['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 = dataFrame.plot.bar(rot=0, 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