Search⌘ K
AI Features

Resampling—Upsample and Downsample

Explore how to resample time series data using pandas to adjust data frequency through upsampling or downsampling. Learn to apply aggregation functions, use interval parameters for precise data grouping, and impute missing values with forward fill, backward fill, or interpolation. Understand how to manage time-based data for accurate and flexible analysis.

Overview

Resampling is a powerful technique used in time series analysis to convert data from one frequency to another. It’s useful when working with time series data that has irregular intervals or when we want to analyze data at a different frequency than the original data.

We can think of resampling as similar to a GroupBy operation, except that we aggregate based on a time frequency. In pandas, resampling is made easy with resample(). The resample() method allows us to change the frequency of our time series data and provides two main types of resampling:

  • Downsampling: Involves reducing the frequency of the data, such as converting daily data to monthly data. This process usually requires an aggregation function to combine the data points within each new interval (e.g., mean, sum, or count) because we’re compressing the data into fewer data points with a lower resolution.

  • Upsampling: Involves increasing the frequency of the data, for example, converting monthly data to daily data. This process may require interpolation or forward/backward filling to fill in the missing data points in the new intervals because we’re expanding the data into more data points with a more ...