Pandas interview question: fill missing dates with zeros

MediumDates and calendar

Problem

Shared data rules

For each city and each day of Sep 1–27, 2026, count cancelled orders placed that day and their total amount. A day with no cancellations is a row of zeros.

Example

Input: orders
order_idcreated_atstatuscityamount_usdRow note
3012026-09-01 11:20cancelledBoston28
3022026-09-01 19:30cancelledBoston18
3032026-09-02 13:00deliveredBoston50← delivered — not a cancellation
3042026-09-03 18:00deliveredWashington22← no cancellations in the city — zeros
Output (excerpt)
cityorder_datecancelled_orderscancelled_amount_usd
Boston2026-09-01246
Boston2026-09-0200
Boston2026-09-0300
Washington2026-09-0100
Washington2026-09-0200
Washington2026-09-0300

This is an excerpt for Sep 1–3; the full answer has 2 × 27 = 54 rows. Boston has two cancellations on Sep 1 for $46, and every other cell is zero.

Solve it free

Your code runs on real pandas in your browser. No sign-up needed.

Skills it tests

More interview questions

All questions