Python
#33

Reshape Data from Wide to Long Format with melt() in Pandas

MediumGoogle
Interview Question #33
Asked at Google

Given a wide financial budget DataFrame with columns `['department', '2026-01', '2026-02', '2026-03']`, unpivot it into a tidy long DataFrame with columns `['department', 'month', 'budget']`.

Input Table: wide_budget
2 rows preview
department2026-012026-02
Marketing5000060000
Engineering120000130000
Expected Output Structure4 rows
departmentmonthbudget
Marketing2026-0150000
Marketing2026-0260000
Engineering2026-01120000
Engineering2026-02130000
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