Aan de slagGa gratis aan de slag

Calculating a rolling sum

Continuing with the London bike-sharing data, hourly rental counts can jump dramatically from one hour to the next, making it hard to spot trends. Rolling statistics smooth out this noise by summing over a window of consecutive rows.

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

Deze oefening maakt deel uit van de cursus

Data Transformation with Polars

Cursus bekijken

Oefeninstructies

  • Add a column rolling_total with the 3-hour rolling sum of rentals.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Add a 3-hour rolling sum of rentals
bikes.with_columns(
    pl.col("rentals").____(window_size=____).alias("____")
)
Code bewerken en uitvoeren