-
-
Save amankharwal/a06a8934875f8fbd369264fc13f7bd51 to your computer and use it in GitHub Desktop.
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
Season_boundaries=batsmen.groupby("season")["batsman_runs"].agg(lambda x: (x==6).sum()).reset_index() | |
fours=batsmen.groupby("season")["batsman_runs"].agg(lambda x: (x==4).sum()).reset_index() | |
Season_boundaries=Season_boundaries.merge(fours,left_on='season',right_on='season',how='left') | |
Season_boundaries=Season_boundaries.rename(columns={'batsman_runs_x':'6"s','batsman_runs_y':'4"s'}) | |
Season_boundaries['6"s'] = Season_boundaries['6"s']*6 | |
Season_boundaries['4"s'] = Season_boundaries['4"s']*4 | |
Season_boundaries['total_runs'] = season['total_runs'] | |
trace1 = go.Bar( | |
x=Season_boundaries['season'], | |
y=Season_boundaries['total_runs']-(Season_boundaries['6"s']+Season_boundaries['4"s']), | |
marker = dict(line=dict(color='#000000', width=1)), | |
name='Remaining runs',opacity=0.6) | |
trace2 = go.Bar( | |
x=Season_boundaries['season'], | |
y=Season_boundaries['4"s'], | |
marker = dict(line=dict(color='#000000', width=1)), | |
name='Run by 4"s',opacity=0.7) | |
trace3 = go.Bar( | |
x=Season_boundaries['season'], | |
y=Season_boundaries['6"s'], | |
marker = dict(line=dict(color='#000000', width=1)), | |
name='Run by 6"s',opacity=0.7) | |
data = [trace1, trace2, trace3] | |
layout = go.Layout(title="Run Distribution per year",barmode='stack',xaxis = dict(tickmode='linear',title="Year"), | |
yaxis = dict(title= "Run Distribution"), plot_bgcolor='rgb(245,245,245)') | |
fig = go.Figure(data=data, layout=layout) | |
iplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment