Calculating rental period end times
Now that you can extract time components, let's manipulate the timestamps themselves. Each bike rental in London lasts up to 45 minutes before incurring extra charges. To analyze when bikes become available again, calculate the end time for each rental period by adding 45 minutes to the start time.
polars is loaded as pl. The DataFrame bikes is available with the time column as a Datetime.
Deze oefening maakt deel uit van de cursus
Data Transformation with Polars
Oefeninstructies
- Add a column
period_endby offsetting thetimecolumn forward by 45 minutes.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Calculate when each rental period ends
bikes.with_columns(
pl.col("time").____.____("____").alias("____")
)