CommencerCommencez gratuitement

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.

Cet exercice fait partie du cours

<cours>Data Transformation with Polars</cours>
Voir le cours

Instructions de l’exercice

  • Group the data by week using group_by_dynamic().
  • Calculate the sum of rentals and name it total_rentals.

Exercice interactif pratique

Essayez cet exercice en complétant ce code d’exemple.

# Group the data by week
bikes.____("time", every="____").agg(
  
    # Calculate the sum of rentals
    pl.col("rentals").____().alias("____")
)
Modifier et exécuter le code