Skip to content

Extract the days from a Duration type

Description

Extract the days from a Duration type

Usage

<Expr>$dt$total_days()

Value

A polars expression

Examples

library("polars")

df <- pl$select(
  date = pl$datetime_range(
    start = as.Date("2020-3-1"),
    end = as.Date("2020-5-1"),
    interval = "1mo1s"
  )
)
df$with_columns(
  diff_days = pl$col("date")$diff()$dt$total_days()
)
#> shape: (2, 2)
#> ┌─────────────────────┬───────────┐
#> │ date                ┆ diff_days │
#> │ ---                 ┆ ---       │
#> │ datetime[μs]        ┆ i64       │
#> ╞═════════════════════╪═══════════╡
#> │ 2020-03-01 00:00:00 ┆ null      │
#> │ 2020-04-01 00:00:01 ┆ 31        │
#> └─────────────────────┴───────────┘