I want to return the name of the country with the maximum number of gold medals in the 'Gold' column.
# Summer Gold Silver Bronze Total # Winter Gold.1 Silver.1 Bronze.1 Total.1 # Games Gold.2 Silver.2 Bronze.2 Combined total ID
Afghanistan 13 0 0 2 2 0 0 0 0 0 13 0 0 2 2 AFG
Algeria 12 5 2 8 15 3 0 0 0 0 15 5 2 8 15 ALG
Argentina 23 18 24 28 70 18 0 0 0 0 41 18 24 28 70 ARG
Armenia 5 1 2 9 12 6 0 0 0 0 11 1 2 9 12 ARM
Australasia 2 3 4 5 12 0 0 0 0 0 2 3 4 5 12 ANZ
The following code returns the row object and I want to extract the name of the country which is the index of that row.
def return_max_name():
return df.loc[df['Gold'].idxmax()]
return_max_name()
Here is what is returned:
# Summer 26
Gold 976
Silver 757
Bronze 666
Total 2399
# Winter 22
Gold.1 96
Silver.1 102
Bronze.1 84
Total.1 282
# Games 48
Gold.2 1072
Silver.2 859
Bronze.2 750
Combined total 2681
ID USA
Name: United States, dtype: object
I want the function to return 'United States'. I am new to Pandas and I am kinda stuck here so any kind of help will be great!
df.Gold.idxmax(). it should give uArgentinabased on ur shared datadf['Gold.1']