# Totals by Week and Month: resample

Total a column by month with groupby on dt.to_period('M'), and by week with resample('W') on a date index, which labels each week by the Sunday it ends on and keeps every week from the first to the last, so a week with no orders shows as 0 instead of disappearing, while its mean is NaN.

![Cheat sheet: Totals by Week and Month: resample](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/d126ee2f4f1449f597005fbed30ae8a5.webp)

- Category: Data Analysis
- Level: Journeyman
- Tags: python, resample(), Time Series, to_period()
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/pandas-resample-cheat-sheet
