开始使用免费开始使用

Calculating the difference from hourly mean

Totals are useful, but deviations tell a richer story. Calculate how much each hour's rentals differ from the average for that hour across all days to quickly flag above-normal or below-normal demand.

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

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

  • Add a column diff_from_avg showing rentals minus the hourly mean of rentals.

交互式实操练习

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

# Calculate how each rental differs from its hourly average
bikes.with_columns(
    (pl.col("rentals") - pl.col("rentals").____().over("____")).alias("____")
)
编辑并运行代码