
Latest order status
mediumLatest 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 Name | Type |
|---|---|
| event_id | int64 |
| order_id | int64 |
| status | str |
| event_time | str |
eventsExample Input
| event_id | order_id | status | event_time |
|---|---|---|---|
| 6 | 5001 | delivered | 2024-09-10 10:02:47 |
| 2 | 5002 | placed | 2024-09-10 09:04:40 |
| 9 | 5002 | out for delivery | 2024-09-10 10:15:09 |
| 1 | 5001 | placed | 2024-09-10 09:00:12 |
| 8 | 5003 | canceled | 2024-09-10 10:07:33 |
| 12 | 5002 | delivered | 2024-09-10 11:01:14 |
| 3 | 5001 | shopping | 2024-09-10 09:12:05 |
| 11 | 5005 | placed | 2024-09-10 10:40:26 |
Example Output
| order_id | status | updated_at |
|---|---|---|
| 5001 | delivered | 2024-09-10 10:02:47 |
| 5002 | delivered | 2024-09-10 11:01:14 |
| 5003 | canceled | 2024-09-10 10:07:33 |
| 5005 | placed | 2024-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.
Company
Instacart
Difficulty
medium
Topic
deduplication
Language
Pandas
Your code
Loading Python in the background. You can start writing.