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.
Latihan ini adalah bagian dari kursus
Data Transformation with Polars
Petunjuk latihan
- Add a column
diff_from_avgshowingrentalsminus the hourly mean ofrentals.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Calculate how each rental differs from its hourly average
bikes.with_columns(
(pl.col("rentals") - pl.col("rentals").____().over("____")).alias("____")
)