Pandasdrill

Level 7: Interview cases Exercise 89 of 102

Repeat customers

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

Marketing wants a list of repeat buyers: customers with at least two completed orders. Return the columns `customer` and `orders` (the number of completed orders), most orders first, and alphabetical by customer when two have the same number.

What this exercise teaches

Count, then filter the counts, then sort by two keys with a direction for each. Counting before removing cancelled orders would promote a customer whose second order never went through.

A hint if you get stuck

Count completed orders per customer first. The rule about two or more is a filter on that count.

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 Interview cases