Extracting the hour component
With the datetime properly parsed, you want to identify when bike demand peaks during the day. To compare rentals across different hours, you need to extract the hour component from each timestamp.
polars is loaded as pl. The DataFrame bikes is available with the time column already parsed as a Datetime.
Latihan ini adalah bagian dari kursus
Data Transformation with Polars
Petunjuk latihan
- Extract the hour from the
timecolumn and name the new columnhour.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Extract the hour from the time column
bikes.with_columns(
pl.col("time").____.____().____("hour")
)