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.
Deze oefening maakt deel uit van de cursus
Data Transformation with Polars
Oefeninstructies
- Calculate the sum of
rentalsgrouped byhourand name the columnhourly_total.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Add the hourly total using a window function
bikes.with_columns(
pl.col("rentals").____().over("____").alias("____")
)