Pandas interview question: find the bugs in an average order value notebook
Problem
Shared data rulesThe colleague’s AOV doesn’t equal revenue divided by the number of orders. For each platform, find September 2026 orders, their revenue and AOV.
Formula
aov = revenue_usd / orders
Code to fix
Fix it free# AOV by platform, September
sept = orders[(orders['status'] == 'delivered')
& (orders['created_at'] >= '2026-09-01')
& (orders['created_at'] < '2026-10-01')].copy()
sept['day'] = sept['created_at'].str[:10]
# revenue, orders and AOV by day
daily = (sept.groupby(['platform', 'day'])
.agg(revenue_usd=('amount_usd', 'sum'),
orders=('order_id', 'count'))
.reset_index())
daily['aov'] = daily['revenue_usd'] / daily['orders']
# platform totals
result = (daily.groupby('platform')
.agg(orders=('orders', 'count'),
revenue_usd=('revenue_usd', 'sum'),
aov=('aov', 'mean'))
.reset_index())
Example
orders| order_id | created_at | status | platform | amount_usd |
|---|---|---|---|---|
| 1 | 2026-09-07 10:00 | delivered | ios | 60 |
| 2 | 2026-09-08 12:00 | delivered | ios | 20 |
| 3 | 2026-09-08 15:00 | delivered | ios | 20 |
| 4 | 2026-09-08 19:00 | delivered | ios | 20 |
| 5 | 2026-09-08 11:00 | delivered | android | 20 |
| 6 | 2026-09-08 18:00 | delivered | android | 28 |
| platform | orders | revenue_usd | aov |
|---|---|---|---|
| ios | 4 | 120 | 30 |
| android | 2 | 48 | 24 |
iOS: $120 over 4 orders, so $30. Android: $48 over 2 orders, so $24.
Output columns
platform- the order’s platform (orders.platform)
Fix it free
Fix the notebook — code checks it on real pandas in your browser. No sign-up needed.