Skip to content

Hours

Source code

Description

Extract the hours from a Duration type.

Usage

<Expr>$dt$total_hours()

Value

Expr of i64

Examples

library("polars")

df = pl$DataFrame(
  date = pl$date_range(
    start = as.Date("2020-1-1"),
    end = as.Date("2020-1-4"),
    interval = "1d"
  )
)
df$select(
  pl$col("date"),
  diff_hours = pl$col("date")$diff()$dt$total_hours()
)
#> shape: (4, 2)
#> ┌────────────┬────────────┐
#> │ date       ┆ diff_hours │
#> │ ---        ┆ ---        │
#> │ date       ┆ i64        │
#> ╞════════════╪════════════╡
#> │ 2020-01-01 ┆ null       │
#> │ 2020-01-02 ┆ 24         │
#> │ 2020-01-03 ┆ 24         │
#> │ 2020-01-04 ┆ 24         │
#> └────────────┴────────────┘