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
rentalsand name ittotal_rentals.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Group the data by week
bikes.____("time", every="____").agg(
# Calculate the sum of rentals
pl.col("rentals").____().alias("____")
)