Demographic Data Analyzer Python data science

Hello everyone I was doing 2nd part of assigments and I am stuck at this one. Even though I solved the majority of the thing issue is with the last question which asks: Identify the most popular occupation for those who earn >50K in India.
top_IN_occupation=df[(df[‘salary’] == ‘>50K’) and (df[‘native-country’] == ‘India’)].sort_values(by="[‘occupation’].count()" , inplace=False).max()
is my answer but this also doesn’t work and creates many errors. Could anyone help?

edit: nevermind I figured it out here is the solution if anyones stuck top_IN_occupation=df[(df[‘salary’] == ‘>50K’) & (df[‘native-country’] == ‘India’)].loc[:,“occupation”].value_counts()[:1].sort_values(ascending=False)
To explain a little first part obviously sorts india and 50> salary then loc part creates a new dataframe just with occupations and value_counts()[:n] where n is the top frequently used n names sorts, in this case I only want the first one and ascending is false since we want most used.

1 Like

Can you explain the second last question, where is it asking highest earning country percentage?

I got the part where it is asking for country with highest earning people, but in the second part we have to calculate percentage of what?