开始使用免费开始使用

Calculating the hourly total with window functions

Continuing with the London bike-sharing data, you want to spot unusual demand patterns like events or disruptions. To do this, compare each hour's rentals to its typical total across all days. Window functions let you add group statistics while keeping every row intact.

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

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

  • Calculate the sum of rentals grouped by hour and name the column hourly_total.

交互式实操练习

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

# Add the hourly total using a window function
bikes.with_columns(
    pl.col("rentals").____().over("____").alias("____")
)
编辑并运行代码