Resampling—Aggregation and Other Parameters
Explore advanced resampling techniques in pandas for handling time series data. Learn to use aggregation methods, customize resampling origins, and apply offsets to align data bins precisely. Gain skills to manipulate and analyze time-indexed data with flexibility and control.
We'll cover the following...
Introduction
Now that we've learned the general use of the resample() method for upsampling and downsampling, let's explore its other capabilities, such as aggregation functions and origin definition. We’ll again use the truncated dataset version of Spain’s 2018 hourly energy demand data.
Preview of Spain 2018 Hourly Energy Demand Data
Time | Generation Fossil Gas | Generation Fossil Hard Coal |
2018-01-01 00:00:00 | 3471 | 996 |
2018-01-01 01:00:00 | 3269 | 959 |
2018-01-01 02:00:00 | 3541 | 1014 |
2018-01-01 03:00:00 | 3450 | 1043 |
2018-01-01 04:00:00 | 3318 | 1063 |
Groupby aggregation functions
Given that resample() is essentially a time-based groupby operation coupled with an aggregation function, we can expect the common groupby functions to be applicable too. For example, the following code demonstrates some of the common aggregation functions that can be applied to each interval group for a downsampling example:
While it’s common to apply a single aggregation function like mean() or ...