Skip to content

Extract the seconds from a Duration type

Description

Extract the seconds from a Duration type

Usage

<Expr>$dt$total_seconds()

Value

A polars expression

Examples

library("polars")

df <- pl$select(date = pl$datetime_range(
  start = as.POSIXct("2020-1-1", tz = "GMT"),
  end = as.POSIXct("2020-1-1 00:04:00", tz = "GMT"),
  interval = "1m"
))
df$with_columns(
  diff_sec = pl$col("date")$diff()$dt$total_seconds()
)
#> shape: (5, 2)
#> ┌─────────────────────────┬──────────┐
#> │ date                    ┆ diff_sec │
#> │ ---                     ┆ ---      │
#> │ datetime[ms, GMT]       ┆ i64      │
#> ╞═════════════════════════╪══════════╡
#> │ 2020-01-01 00:00:00 GMT ┆ null     │
#> │ 2020-01-01 00:01:00 GMT ┆ 60       │
#> │ 2020-01-01 00:02:00 GMT ┆ 60       │
#> │ 2020-01-01 00:03:00 GMT ┆ 60       │
#> │ 2020-01-01 00:04:00 GMT ┆ 60       │
#> └─────────────────────────┴──────────┘