开始使用免费开始使用

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.

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

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

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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")
)
编辑并运行代码