Pandasdrill

Level 7: Interview cases Exercise 90 of 102

Month over month revenue growth

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

Finance asks how revenue changed from month to month. Using completed orders only, return one row per month with the columns `month` (text like `2024-01`), `revenue` and `growth`, where growth is the change from the previous month as a fraction (0.25 means up 25%). The first month has no growth value.

What this exercise teaches

Grouping by a formatted date gives one row per month in calendar order, because the text sorts like the dates do. pct_change divides each value by the previous one and subtracts 1. The first month stays missing: there is nothing to compare it with, and a 0 there would claim that revenue was flat.

A hint if you get stuck

Turn each date into its month, total the revenue per month, then compare each month with the one before it.

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