polars.internals.series.datetime.DateTimeNameSpace.timestamp#

DateTimeNameSpace.timestamp(tu: TimeUnit = 'us') pli.Series[source]#

Return a timestamp in the given time unit.

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

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.timestamp().alias("timestamp_us")
shape: (3,)
Series: 'timestamp_us' [i64]
[
        978307200000000
        978393600000000
        978480000000000
]
>>> date.dt.timestamp(tu="ns").alias("timestamp_ns")
shape: (3,)
Series: 'timestamp_ns' [i64]
[
        978307200000000000
        978393600000000000
        978480000000000000
]