开始使用免费开始使用

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.

本练习是课程的一部分

Data Transformation with Polars

查看课程

练习说明

  • Add a column period_end by offsetting the time column forward by 45 minutes.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Calculate when each rental period ends
bikes.with_columns(
    pl.col("time").____.____("____").alias("____")
)
编辑并运行代码