This tutorial explains how to aggregate time series data in pandas using the gold and silver price data from rdatasets.
The documentation for each package used in this tutorial is linked below:
Open up a Jupyter notebook and import the following:
The data is from rdatasets imported using the Python package statsmodels.
The pandas function resample can be used to create aggregations on specified windows. Here, a weekly aggregate of the daily gold and silver price data will be created.
First, a datetime index needs to be created from the date column.
The parameter origin is used to specify the day of week to start the aggregation on. January 1, 1978 is a Sunday, so each of these aggregations will start on Sunday and aggregate over the subsequent week.