pythonbeginner

Pandas Time-Series Resampling

Resample time-series data from daily to weekly/monthly frequencies with aggregation functions.

python
import pandas as pd
import numpy as np

idx = pd.date_range('2024-01-01', periods=365, freq='D')
df = pd.DataFrame({'revenue': np.random.randint(100, 1000, 365)}, index=idx)

weekly  = df.resample('W').sum()
monthly = df.resample('ME').agg({'revenue': ['sum', 'mean', 'max']})

print('Weekly:\n', weekly.head())
print('Monthly:\n', monthly)

Use Cases

  • time-series analytics
  • reporting dashboards
  • KPI aggregation

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.