polars.Expr.dt.total_nanoseconds#

Expr.dt.total_nanoseconds() Expr[source]#

Extract the total nanoseconds from a Duration type.

Returns:
Expr

Expression of data type Int64.

Examples

>>> from datetime import datetime
>>> df = pl.DataFrame(
...     {
...         "date": pl.datetime_range(
...             datetime(2020, 1, 1),
...             datetime(2020, 1, 1, 0, 0, 1, 0),
...             "200ms",
...             eager=True,
...         ),
...     }
... )
>>> df.select(
...     pl.col("date"),
...     milliseconds_diff=pl.col("date").diff().dt.total_nanoseconds(),
... )
shape: (6, 2)
┌─────────────────────────┬───────────────────┐
│ date                    ┆ milliseconds_diff │
│ ---                     ┆ ---               │
│ datetime[μs]            ┆ i64               │
╞═════════════════════════╪═══════════════════╡
│ 2020-01-01 00:00:00     ┆ null              │
│ 2020-01-01 00:00:00.200 ┆ 200000000         │
│ 2020-01-01 00:00:00.400 ┆ 200000000         │
│ 2020-01-01 00:00:00.600 ┆ 200000000         │
│ 2020-01-01 00:00:00.800 ┆ 200000000         │
│ 2020-01-01 00:00:01     ┆ 200000000         │
└─────────────────────────┴───────────────────┘