Pandas interview question: cart-to-order conversion
Problem
Shared data rulesFind cart-to-order conversion by day and platform for Sep 14–27, 2026. A user with add_to_cart counts as converted if they also have order_placed on the same day and platform.
Formulas
conversion = order_users / cart_userscart_events— how many timescart_usersadded to cart; a duplicate (same user, time and platform) counts once
Example
events| event_id | user_id | event_ts | event_name | platform | Row note |
|---|---|---|---|---|---|
| 1 | 1 | 2026-09-20 11:00 | add_to_cart | web | |
| 2 | 1 | 2026-09-20 11:00 | add_to_cart | web | ← duplicate of event 1 |
| 3 | 1 | 2026-09-20 11:12 | order_placed | web | |
| 4 | 2 | 2026-09-20 15:40 | add_to_cart | web | |
| 5 | 2 | 2026-09-20 16:05 | add_to_cart | web | |
| 6 | 2 | 2026-09-21 10:10 | order_placed | web | ← next day — doesn’t count |
| 7 | 3 | 2026-09-20 18:30 | order_placed | ios | ← order with no cart — doesn’t count |
- Event 2: duplicate of event 1
- Event 6: next day — doesn’t count
- Event 7: order with no cart — doesn’t count
| day | platform | cart_events | cart_users | order_users | conversion |
|---|---|---|---|---|---|
| 2026-09-20 | web | 3 | 2 | 1 | 0.5 |
Sep 20: 3 add-to-carts by 2 users; only user 1 also ordered that day: 1 / 2 = 0.5.
Solve it free
Your code runs on real pandas in your browser. No sign-up needed.
Skills it tests
More interview questions
- Pandas: Rolling 7-day revenueEasy · Rolling aggregates
- Pandas: Find the bugs in an average order value notebookEasy · Code review
- Python: Find the bugs in a median functionEasy · Code review
- SQL: Second-highest price in each groupEasy · Nth-highest value
- SQL: Top 3 categories in each cityMedium · Top-N per group