Pandas interview question: wide-to-long reshaping
Problem
Shared data rulesTurn the deliveries of orders placed Sep 7–13, 2026, into a long table: one row per delivery stage. Skip a stage with no recorded time.
Example
orders| order_id | created_at | Row note |
|---|---|---|
| 301 | 2026-09-07 10:40 | |
| 302 | 2026-09-10 11:00 | |
| 303 | 2026-09-14 10:10 | ← Sep 14 — outside the week |
- Order 303: Sep 14 — outside the week
deliveries| order_id | assigned_at | picked_at | delivered_at | Row note |
|---|---|---|---|---|
| 301 | 2026-09-07 10:45 | NULL | 2026-09-07 11:30 | ← pickup not recorded |
| 302 | 2026-09-10 11:03 | 2026-09-10 11:15 | 2026-09-10 11:41 | |
| 303 | 2026-09-14 10:12 | 2026-09-14 10:25 | 2026-09-14 10:58 |
- Order 301: pickup not recorded
| order_id | stage | stage_ts |
|---|---|---|
| 301 | assigned | 2026-09-07 10:45 |
| 301 | delivered | 2026-09-07 11:30 |
| 302 | assigned | 2026-09-10 11:03 |
| 302 | picked | 2026-09-10 11:15 |
| 302 | delivered | 2026-09-10 11:41 |
Delivery 301 gives two rows and 302 gives three.
Output columns
stage- 'assigned', 'picked' or 'delivered' — from assigned_at, picked_at, delivered_at
Solve it free
Your code runs on real pandas in your browser. No sign-up needed.
Skills it tests
More interview questions
- Pandas: Detect dirty product names by groupEasy · Strings and text
- Pandas: RFM customer segmentationHard · Median and percentiles
- Pandas: UTC timestamps to local datesEasy · Time zones
- Pandas: Find the bugs in outlier cappingMedium · Code review
- Pandas: Fill missing dates with zerosMedium · Dates and calendar