Pandas resample turns daily data into monthly, quarterly or yearly summaries in one line. This guide uses ten years of real daily temperatures to show how resample works, where it surprises people, and how it differs from a rolling window.
Load a daily series with a date index
The data is the Daily Minimum Temperatures series for Melbourne: one reading per day from 1 January 1981 to 31 December 1990. Resample only works on a datetime index, so parse the dates and set them as the index.
import pandas as pd
df = pd.read_csv("daily-min-temperatures.csv", parse_dates=["Date"], index_col="Date")
s = df["Temp"]
print(s.shape, s.index.min().date(), s.index.max().date(), s.isna().sum())That gives 3,650 readings with no missing values and a sorted index. Ten years should have 3,652 days, though, so look for hidden gaps:
full = pd.date_range(s.index.min(), s.index.max(), freq="D")
print(list(full.difference(s.index).date))Two days are absent, 31 December 1984 and 31 December 1988 (both leap years). isna() cannot see them because the rows do not exist. Keep that in mind: a series can be complete in the sense of having no NaN and still have gaps.
Resample to months, quarters and years
monthly = s.resample("MS").mean()
yearly = s.resample("YS").mean().round(2)
quarterly = s.resample("QS").agg(["mean", "min", "max", "count"]).round(2)resample("MS") groups the days into months labelled by the first of the month and averages them. The result has 120 months. The coldest monthly average is 4.64 °C (July 1982) and the warmest is 17.71 °C (January 1981). Yearly means range from 10.59 (1984) to 11.97 (1988).
agg computes several statistics at once. For the first quarter of 1981 it returns a mean of 16.25, a minimum of 8.0, a maximum of 25.0 and a count of 90 days; the second quarter has a mean of 9.72 and 91 days. Always include count so you know how many days stand behind each number.

Frequency aliases that trip people up
Month and year aliases come in start and end versions. In pandas 3.0.5 the old "M" and "Y" raise an error, and you must choose explicitly:
"MS"and"YS": labels at the period start (1981-01-01)."ME"and"YE": labels at the period end (1981-01-31)."W": weeks ending on Sunday. The first label here is 1981-01-04, so the first “week” holds only four days (Thursday to Sunday).
Pick one and keep it across your project so charts and joins line up. If you later merge resampled tables, merging with pandas needs the same labels on both sides.
Fill the gaps before resampling
s2 = s.asfreq("D") # inserts the two missing days as NaN
s3 = s2.interpolate("time") # straight line between neighbours
print(s3["1984-12-31"], s3["1988-12-31"])The two gaps become 14.85 (between 16.4 and 13.3) and 14.2 (between 14.1 and 14.3). Linear interpolation is reasonable for two single days in a smooth series, but it would hide a long outage, so inspect the size of any gap before you fill it.
Resample vs rolling
Resample collapses many rows into one per period. A rolling window keeps one row per day and smooths it. For July 1984, the 30-day time-based rolling mean at 31 July is 5.93 °C, while the calendar-month mean for July 1984 is 5.99 °C. They are close but not the same, because the window covers the last 30 days, not the calendar month.
s.rolling("30D").mean().loc["1984-07-31"] # 5.93
s["1984-07"].mean() # 5.99A count-based rolling(30) gives no value until the thirtieth row (1981-01-30), leaving 3,621 smoothed points. Use resample for reporting and rolling for trend lines. For forecasting these series, see time series analysis in Python.
Upsampling
Going from months to days creates new rows, so you must decide what to put in them. monthly.resample("D").ffill() repeats the January 1981 value (17.71) for every day of the month. That is a step function, not a measurement, so label it clearly in any chart.
Reference: pandas time series user guide. More pandas: groupby and pivot tables.
FAQ
What is the difference between resample and groupby?
Resample groups by time period on a datetime index and keeps empty periods. Groupby can group by any column, such as month number across years, which is how the chart above (all Januaries together) was built.
Why does my monthly mean look off?
Check the count per period. In this data every month has 28 to 31 days, so the means are reliable. With gaps, a month can rest on a handful of days.
Which versions were used?
pandas 3.0.5 and Python 3.13. Output is from a real run; results are specific to this one station.
