text_html_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

medals = pd.read_csv('../input/.csv')

counted = medals.pivot_table(index='NOC', values='Athlete', columns='Medal', aggfunc='count')
counted['totals'] = counted.sum(axis='columns')
counted = counted.sort_values('totals', ascending=False)

counted = medals.pivot_table(index='NOC', values='Athlete', columns='Medal', aggfunc='count', margins=True, margins_name='Totals_all')
counted = counted.sort_values('Totals_all', ascending=False)

medals_by_gender = medals.groupby(['Event_gender', 'Gender']).count()
medals_by_gender

boolean_filter = (medals.Event_gender == 'W') & (medals.Gender == 'Men')
medals[boolean_filter]

medals.iloc[[23675]]

medals.iloc[[23675], [6]] = 'Women'
medals.iloc[[23675]]

Nsports = medals[['NOC', 'Sport']].groupby('NOC', as_index=False).agg({'Sport': 'nunique'}).sort_values('Sport', ascending=False)

during_cold_war = (medals.Edition >= 1952) & (medals.Edition <= 1988)
is_usa_urs = medals.NOC.isin(['USA', 'URS'])
cold_war_medals = medals.loc[during_cold_war & is_usa_urs]
country_grouped = cold_war_medals.groupby('NOC')
Nsports = country_grouped['Sport'].nunique().sort_values(ascending=False)

medals_won_by_country = medals.pivot_table(index='Edition', columns='NOC', values='Athlete', aggfunc='count')
cold_war_usa_usr_medals = medals_won_by_country.loc[1952:1988, ['USA', 'URS']]
print('Consistency during cold war\n', cold_war_usa_usr_medals.idxmax(axis='columns'))
print('\nTotal counts\n', cold_war_usa_usr_medals.idxmax(axis='columns').value_counts())