Pandas interview question: find the bugs in an average order value notebook

EasyCode review

Problem

Shared data rules

The 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

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

Input: orders
order_idcreated_atstatusplatformamount_usd
12026-09-07 10:00deliveredios60
22026-09-08 12:00deliveredios20
32026-09-08 15:00deliveredios20
42026-09-08 19:00deliveredios20
52026-09-08 11:00deliveredandroid20
62026-09-08 18:00deliveredandroid28
Expected output
platformordersrevenue_usdaov
ios412030
android24824

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.

Skills it tests

More interview questions

All questions