Latest order status

deduplication

Latest order status

Instacart Pandas Interview Question

Instacart logs an event every time an order changes status, but the events are not stored in time order. The support team needs each order's current status.

Using the events DataFrame, find each order's most recent status. Show the order_id, the status and the time of that event as updated_at. Assign the answer to result.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Engineer
  • Data Scientist
  • ML Engineer

eventsDataFrame12 rows

Column NameType
event_idint64
order_idint64
statusstr
event_timestr

eventsExample Input

event_idorder_idstatusevent_time
65001delivered2024-09-10 10:02:47
25002placed2024-09-10 09:04:40
95002out for delivery2024-09-10 10:15:09
15001placed2024-09-10 09:00:12
85003canceled2024-09-10 10:07:33
125002delivered2024-09-10 11:01:14
35001shopping2024-09-10 09:12:05
115005placed2024-09-10 10:40:26

Example Output

order_idstatusupdated_at
5001delivered2024-09-10 10:02:47
5002delivered2024-09-10 11:01:14
5003canceled2024-09-10 10:07:33
5005placed2024-09-10 10:40:26

Explanation

Order 5002 was placed, then out for delivery, then delivered at 11:01 a.m., so its latest status is delivered. The events are not stored in time order, so the latest one has to be found by its time rather than by its position in the table.

The example above is a small slice of the data. Your code runs against the full DataFrames.