Fill Missing Days and Roll Up by Week

medium
Unit 10 · Pandas III0/2 to milestone

Sales logs only have rows for days with sales. Before you can plot or model them, you need every day, then weekly totals.

df has a date column (strings like "2024-03-04") and an amount column, possibly with several rows per day.

Implement:

  • fill_daily(df): one row per calendar day from the first to the last date, with date (string) and amount (the day's total, 0.0 for days without sales), sorted by date, with a fresh 0…n−1 index
  • weekly_totals(df): a dict from each Monday ("YYYY-MM-DD") to that Monday-to-Sunday week's total. Include every week from the one containing the first date to the one containing the last date, even weeks with no sales.
#pandas#time-series#resampling2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Fill Missing Days and Roll Up by Week · TechGradify