Python
#37

Reshape Hierarchical Series with unstack() in Pandas

Medium
Interview Question #37

Given a multi-index Series resulting from `df.groupby(['year', 'quarter'])['sales'].sum()`, pivot 'quarter' into column headers using `.unstack()`.

Input Table: multi_series
3 rows preview
yearquartersales
2025Q1100
2025Q2150
2026Q1120
Expected Output Structure2 rows
yearQ1Q2
2025100150
2026120NULL
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

Python 3.10 (Pandas)
Environment Ready

Click "Run & Test" to execute your Pandas code against the test assertions.

Chat with us