Pandasdrill

Level 3: Aggregating Exercise 44 of 102

Distinct values per group with nunique

A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.

The task

For each region, how many different products were sold? Return a Series indexed by region.

What this exercise teaches

count returns how many orders a region has, nunique how many different products are among them. This is the pandas version of COUNT(DISTINCT ...) in SQL.

A hint if you get stuck

nunique counts the different values in each group. count counts the rows.

Try it now, free, no account needed

Your first 8 exercises on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro unlocks every exercise, timed mode and the certificate.

Open this exercise

More exercises in Aggregating