0

I have a dataframe with indexes names of countries and columns medals. I want to get the name of the country with the most number of gold medals. I've tried this :

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index
answer_one()

I want to get just the string which is the name of the country but instead I keep getting this

Index(['United States'], dtype='object')

2 Answers 2

1
def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values[0]
answer_one()
Sign up to request clarification or add additional context in comments.

Comments

1

As you want the concrete value, I would use the following code:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values[0]
answer_one()

This will return the first max country. If you want an array of all max countries:

def answer_one():
    x= df[df['Gold.2']==df['Gold.2'].max()]
    return x.index.values
answer_one()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.