Python Data Analysis: demographic

I have my test passing up to this point, but I keep getting United states as the country with the most earners over 50K. Can I get some clarification on what they want? Do I need to calculate the amount of people in the dataframe per-country, and then calculate the percentage of them that earn over 50K?

    # What country has the highest percentage of people that earn >50K?

    wealths = df[df['salary'] == ">50K"]
    most = wealths.groupby('native-country')

    
    highest_earning_country = most['native-country'].value_counts().idxmax()
    print('higher earning countrys = ', highest_earning_country)
   # here I get ('United States', 'United States')  not Iran.

Thanks in advance. Panda is still quite new to me.

(get the unique values of countries with salary >50k / unique values of countries )* 100).idxmax()

idxmax() gets the 1st occurence of that unique value.

1 Like