Assignment 3 - Question 4 - Most Populous DF

Q4: Create a dataframe containing 10 countries with the highest population.

most_populous_df = countries_df.sort_values(‘population’,ascending = False)

I am getting failed in this question only - Q4: FAIL The value of ‘most_populous_df’ is incorrect.

I cant figure out what is wrong with my code.

I guess the head(10) should be included in the above code only. Or you can also reassign,
most_populous_df = most_populous_df.head(10)

Note: You can also try to use use ['population'] for the same.
I hope it helps (:


Thank you but I dont think I am getting the wrong results with my code. Not sure why it keeps failing me.

I think @bhupeshchandrawanshi is right. If you look at the assignment, it expects most_populous_df as the dataframe with the 10 countries with the highest population. Whereas your most_populous_df contains sorted dataframe of all countries.

Here is a screenshot of the assignment for your reference:

1 Like