Demographic Data Analyzer - What country has the highest percentage of people that earn >50K? (Code attached)

Tell us what’s happening:
I managed to find the highest % of high earners for each country. However, I managed to do it in three lines of code (code below) instead of two lines.

Can someone provide me with some guidance in terms of how I can get the result in two lines of code?

  • highest_earning_country
  • highest_earning_country_percentage

Thank you!

Your code so far
highest_earning_country = df[df[“salary”]==">50K"].groupby([“native-country”]).size()/df.groupby([“native-country”])[“salary”].size()

highest = highest_earning_country.reset_index(name= “% of high earner”)

maxincome = highest[highest["% of high earner"]== max(highest["% of high earner"])]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Demographic Data Analyzer

Link to the challenge:

I mean, you could just chain the commands. Although that would be hard to read and generally “less lines of code” is not a goal to aim for, if you loose readability.

However I’d think resetting the index is not necessary.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.