Pandas interview question: wide-to-long reshaping

EasyPivot and unpivot

Problem

Shared data rules

Turn 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

Input: orders
order_idcreated_atRow note
3012026-09-07 10:40
3022026-09-10 11:00
3032026-09-14 10:10← Sep 14 — outside the week
Input: deliveries
order_idassigned_atpicked_atdelivered_atRow note
3012026-09-07 10:45NULL2026-09-07 11:30← pickup not recorded
3022026-09-10 11:032026-09-10 11:152026-09-10 11:41
3032026-09-14 10:122026-09-14 10:252026-09-14 10:58
Output
order_idstagestage_ts
301assigned2026-09-07 10:45
301delivered2026-09-07 11:30
302assigned2026-09-10 11:03
302picked2026-09-10 11:15
302delivered2026-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

All questions