Skip to content
C

Group Sales by Region

Mediumpython

Given sales data with region and amount columns, group by region and calculate the total sales per region.

Approach: build the DataFrame, then df.groupby("region")["amount"].sum(), ordered by region name for a predictable result.

Input: First line: the number of sales records n. Next n lines: region,amount.

Output: One line per region: a tuple (region, total), ordered alphabetically by region.

Input (stdin)

Output

Run your code to see output here...