ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Data Transformation with Polars

Ver curso

Instrucciones del ejercicio

  • Add a column diff_from_avg showing rentals minus the hourly mean of rentals.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Calculate how each rental differs from its hourly average
bikes.with_columns(
    (pl.col("rentals") - pl.col("rentals").____().over("____")).alias("____")
)
Editar y ejecutar código