Created
October 17, 2018 17:53
-
-
Save nescobar/c905a33c374cad1511c4bfbe61b46347 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Unique number of players that won GS and Masters per period | |
s = tennis_df[(tennis_df['round']=='F')&(tennis_df['tourney_level'].isin(['G']))&(tennis_df['tourney_year'].between('1975','1985'))].agg({'winner_name':'nunique'}) | |
t = tennis_df[(tennis_df['round']=='F')&(tennis_df['tourney_level'].isin(['G']))&(tennis_df['tourney_year'].between('1986','1996'))].agg({'winner_name':'nunique'}) | |
u = tennis_df[(tennis_df['round']=='F')&(tennis_df['tourney_level'].isin(['G']))&(tennis_df['tourney_year'].between('1997','2007'))].agg({'winner_name':'nunique'}) | |
v = tennis_df[(tennis_df['round']=='F')&(tennis_df['tourney_level'].isin(['G']))&(tennis_df['tourney_year'].between('2008','2018'))].agg({'winner_name':'nunique'}) | |
s['1975-1985'] = s['winner_name'] | |
s=s.drop('winner_name') | |
t['1986-1996'] = t['winner_name'] | |
t=t.drop('winner_name') | |
u['1997-2007'] = u['winner_name'] | |
u=u.drop('winner_name') | |
v['2008-2018'] = v['winner_name'] | |
v=v.drop('winner_name') | |
dfl = [s,t,u,v] | |
dfs = pd.concat(dfl) | |
x=pd.DataFrame(dfs, columns=['Unique_Count']).reset_index() | |
x.columns=['Year range','Unique winners'] | |
ax=x.plot('Year range', 'Unique winners', kind='bar', title='Unique # of Players that Won GS Finals', legend=False) | |
ax.set_ylim(0,20) | |
for i, v in enumerate(x['Unique winners']): | |
ax.text(i-0.1, v+0.6, str(v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment