← All Python interview questions

Revenue by city with GroupBy

MediumPandas — GroupBySwiggyDunzo

You have an orders DataFrame and the city lead wants total revenue per city, biggest first.

Write a function revenue_by_city(df) that returns a Series indexed by city holding the summed amount, sorted from highest to lowest revenue.

Practising alone only goes so far — our live cohorts pair Python and Pandas depth with dashboards, agentic analytics projects and mock interviews.

Explore the program