Applying rolling window calculations
Rolling calculations such as rolling sum and average are essential for grasping the dynamics within time series data, offering valuable insights into trends, patterns, and anomalies across varying time spans. Rolling calculations serve as a fundamental tool in the analysis of time series data.
In this recipe, we’ll look at how to apply rolling calculations using Polars’ built-in methods.
How to do it...
Here’s how to apply rolling calculations.
- Let’s see how you can calculate the rolling average of the temperature using the built-in
.
rolling_mean()
method:(     lf     .select(         'datetime',         'temperature',         pl.col('temperature').rolling_mean(3).alias('3hr_rolling_avg')    ...