Group Sales by Region
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.
3 North,100 South,200 North,150
('North', 250)
('South', 200)- 1 <= n <= 1000
Hint 1
df.groupby("region")["amount"].sum() adds up amount within each region group, directly parallel to SQL's GROUP BY.
Hint 2
The result is a Series indexed by region — sorting it by index keeps the printed order predictable.
Hint 3
result.items() lets you loop over (region, total) pairs.
df.groupby("region")["amount"].sum() collapses all rows sharing the same region into one total each — the Pandas equivalent of SQL's GROUP BY + SUM(). Sorting the result by region (its index) before printing keeps the output in a predictable, repeatable order regardless of the input's original row order.