Back to Practice
#0137
Wide Monthly Sales to Long
MediumPandas25 min20 XP
Problem
Given product, jan, feb columns, return product, month, sales rows. Month values should be jan and feb.
Why This Matters
Tidy long format makes plotting, grouping, and modeling easier.
Function Signature
def sales_wide_to_long(df):
Examples
Example 1
Inputproduct A with jan=10 feb=20
Outputtwo rows for A
Each month column becomes a row.
Constraints
- Return the exact requested structure.
- Handle normal edge cases cleanly.
- Prefer readable code over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputproduct A with jan=10 feb=20
Expectedtwo rows for A
Each month column becomes a row.
Hidden Test Categories
multiple productszero salesindex reset