数据集看起来像这样-
Athlete Country Year Sport Gold Silver Bronze Total
0 Yang Yilin China 2008 Gymnastics 1 0 2 3
1 Leisel Jones Australia 2000 Swimming 0 2 0 2
2 Go Gi-Hyeon South Korea 2002 Short-Track Speed Skating 1 1 0 2
3 Chen Ruolin China 2008 Diving 2 0 0 2
4 Katie Ledecky United States 2012 Swimming 1 0 0 1
5 Ruta Meilutyte Lithuania 2012 Swimming 1 0 0 1
6 Dániel Gyurta Hungary 2004 Swimming 0 1 0 1
7 Arianna Fontana Italy 2006 Short-Track Speed Skating 0 0 1 1
8 Olga Glatskikh Russia 2004 Rhythmic Gymnastics 1 0 0 1
9 Kharikleia Pantazi Greece 2000 Rhythmic Gymnastics 0 0 1 1
10 Kim Martin Sweden 2002 Ice Hockey 0 0 1 1
11 Kyla Ross United States 2012 Gymnastics 1 0 0 1
12 Gabriela Dragoi Romania 2008 Gymnastics 0 0 1 1
13 Tasha Schwikert-Warren United States 2000 Gymnastics 0 0 1 1
14 Yang Yun China 2000 Gymnastics 0 0 1 1
这就是我现在正在做的事情,如何只打印国家,年份和总奖牌(每年最多)
gk=df1.groupby('Year')
for Year,Year_df in gk:
print(Year)
print(Year_df.groupby('Country')['Total'].sum())