ComeçarComece de graça

Rolling aggregations on multiple columns

What if you need rolling statistics on multiple columns at once? The .rolling() method lets you compute aggregations over a time-based window for several columns simultaneously.

polars is loaded as pl. The DataFrame bikes is available with columns time, rentals, and temp.

Este exercício faz parte do curso

Data Transformation with Polars

Ver curso

Instruções do exercício

  • Set up the 3-hour rolling window on the time column.
  • Calculate the sum of rentals and the mean of temp in the aggregation.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Set up the 3-hour rolling window
bikes.rolling(index_column="____", period="____").agg(
  
    # Calculate sum of rentals and mean of temp
    pl.col("rentals").____().alias("rolling_total"),
    pl.col("temp").____().alias("rolling_mean_temp")
)
Editar e executar o código