polars.internals.series.datetime.DateTimeNameSpace.second#

DateTimeNameSpace.second(fractional: bool = False) Series[source]#

Extract seconds from underlying DateTime representation.

Applies to Datetime columns.

Returns the integer second number from 0 to 59, or a floating point number from 0 < 60 if fractional=True that includes any milli/micro/nanosecond component.

Returns:
Second part as UInt32 (or Float64)

Examples

>>> from datetime import datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2001, 1, 1, 0, 0, 4)
>>> date = pl.date_range(start, stop, interval="500ms")
>>> date
shape: (9,)
Series: '' [datetime[μs]]
[
        2001-01-01 00:00:00
        2001-01-01 00:00:00.500
        2001-01-01 00:00:01
        2001-01-01 00:00:01.500
        2001-01-01 00:00:02
        2001-01-01 00:00:02.500
        2001-01-01 00:00:03
        2001-01-01 00:00:03.500
        2001-01-01 00:00:04
]
>>> date.dt.second()
shape: (9,)
Series: '' [u32]
[
        0
        0
        1
        1
        2
        2
        3
        3
        4
]
>>> date.dt.second(fractional=True)
shape: (9,)
Series: '' [f64]
[
        0.0
        0.5
        1.0
        1.5
        2.0
        2.5
        3.0
        3.5
        4.0
]