Skip to content

Seconds

Source code

Description

Extract the seconds from a Duration type.

Usage

<Expr>$dt$total_seconds()

Value

Expr of i64

Examples

library("polars")

df = pl$DataFrame(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$select(
  pl$col("date"),
  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       │
#> └─────────────────────────┴──────────┘