Data Analysis with Python Projects - Demographic Data Analyzer

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

list_more50k = df.loc[df['salary'] == '>50K']['native-country'].value_counts()
perc_list_more50k = round(list_more50k / df['native-country'].value_counts(),1)

highest_earning_country = perc_list_more50k.idxmax()
highest_earning_country_percentage = format((list_more50k.max() / df['native-country'].count()) * 100,'.1f')

But it always shows: ‘Cambodia’ != ‘Iran’

May I ask what’s wrong?

MOD EDIT: Link to project:
https://www.freecodecamp.org/learn/data-analysis-with-python/data-analysis-with-python-projects/demographic-data-analyzer

The problem is your rounding.

Print perc_list_more50k and look at it. It doesn’t have enough precision to compare countries.

Cambodia                      0.4
Canada                        0.3
China                         0.3
Iran                          0.4

Thank you! And I’ve successfully solved several other errors as well.

1 Like