Intermediate
Summarise sales with groupby
Write city_totals(df). df is a pandas table (DataFrame) with columns city, qty (how many sold) and price (price of one). Each row's revenue is qty * price. Return a pandas Series with one number per city: that city's total revenue over all its rows, sorted from highest to lowest. For the example below the cities come out in the order Pune, Delhi, Mumbai.
Do not change the DataFrame that was passed in (do not add a revenue column to it).
What Check tests
- The cities come back from highest to lowest revenue
- The totals are correct
- The input DataFrame is unchanged
- Rows of the same city that are not next to each other are added together
- It works for a single city
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.