← All Python interview questions

Pivot monthly revenue by city for the leadership deck

MediumPandas — GroupBySwiggyNykaa

Leadership wants a wide table: one row per city, one column per month, revenue in each cell and zero where a city had no orders that month.

Write monthly_revenue(df) that returns a DataFrame indexed by city, with month numbers (1, 2, 3, 4) as columns and the summed amount as values. Missing combinations must be 0.0, and both the index and the columns must be sorted ascending.