Session Ready
Exercise

Using .nunique() to rank by distinct sports

You may want to know which countries won medals in the most distinct sports. The .nunique() method is the principal aggregation here. Given a categorical Series S, S.nunique() returns the number of distinct categories.

Instructions
100 XP
  • Group medals by 'NOC'.
  • Compute the number of distinct sports in which each country won medals. To do this, select the 'Sport' column from country_grouped and apply .nunique().
  • Sort Nsports in descending order with .sort_values() and ascending=False.
  • Print the first 15 rows of Nsports. This has been done for you, so hit 'Submit Answer' to see the result.