Data Science
Time-Series: Resampling and Rolling
SQL Mastery Team
May 16, 2026
6 min read
Welcome to **Day 115**. Today we do advanced time-series math.
Resampling: The Time-Based GroupBy
If شما have daily data but want a monthly report, use `.resample()`. (Note: The date must be the Index).
# Group by Month and get the Sum
monthly_data = df.resample('M').sum()
Rolling: Moving Averages (Day 66 in SQL!)
Remember our SQL window functions? Here is the Pandas version:
# 7-day moving average of sales
df['7day_avg'] = df['sales'].rolling(window=7).mean()
Why this is powerful
You can see "Trends" instantly. By resampling to a 'W' (Weekly) or 'M' (Monthly) frequency, you remove the noise of individual days and see the actual growth of your business.
Your Task for Today
Calculate a 30-day rolling average for a stock price dataset.
*Day 116: Applying Custom Functions with .apply().*