开始使用免费开始使用

Calculating weekly rental totals

Beyond filtering, you often need to aggregate data by time periods. To spot trends across July and compare week-over-week demand, calculate weekly rental totals.

polars is loaded as pl. The DataFrame bikes is available, sorted by time.

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

  • Group the data by week using group_by_dynamic().
  • Calculate the sum of rentals and name it total_rentals.

交互式实操练习

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

# Group the data by week
bikes.____("time", every="____").agg(
  
    # Calculate the sum of rentals
    pl.col("rentals").____().alias("____")
)
编辑并运行代码