polars.internals.series.datetime.DateTimeNameSpace.epoch#

DateTimeNameSpace.epoch(tu: EpochTimeUnit = 'us') pli.Series[source]#

Get the time passed since the Unix EPOCH in the give time unit.

Parameters:
tu{‘us’, ‘ns’, ‘ms’, ‘s’, ‘d’}

Time unit.

Examples

>>> from datetime import datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2001, 1, 3)
>>> date = pl.date_range(start, stop, interval="1d")
>>> date
shape: (3,)
Series: '' [datetime[μs]]
[
        2001-01-01 00:00:00
        2001-01-02 00:00:00
        2001-01-03 00:00:00
]
>>> date.dt.epoch().alias("epoch_ns")
shape: (3,)
Series: 'epoch_ns' [i64]
[
        978307200000000
        978393600000000
        978480000000000
]
>>> date.dt.epoch(tu="s").alias("epoch_s")
shape: (3,)
Series: 'epoch_s' [i64]
[
        978307200
        978393600
        978480000
]