Pandasdrill

Level 7: Interview cases Exercise 95 of 102

Second order within 30 days

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

Retention asks: what share of customers placed a second order within 30 days of their first one? Count every order, whatever its status, and divide by all customers who have ordered at least once. Return a single number between 0 and 1.

What this exercise teaches

Subtracting two Series lines them up by customer, so customers without a second order get a missing gap, and a missing gap is never <= 30. The denominator is every customer who ordered. Dividing by only those who came back is the common mistake, and it makes retention look better than it is.

A hint if you get stuck

Find each customer's first order date and their second order date, then the days between them. Customers with a single order count in the total but can never qualify.

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