polars.internals.series.datetime.DateTimeNameSpace.hour#

DateTimeNameSpace.hour() Series[source]#

Extract the hour from the underlying DateTime representation.

Applies to Datetime columns.

Returns the hour number from 0 to 23.

Returns:
Hour part as UInt32

Examples

>>> from datetime import datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2001, 1, 1, 3)
>>> date = pl.date_range(start, stop, interval="1h")
>>> date
shape: (4,)
Series: '' [datetime[μs]]
[
        2001-01-01 00:00:00
        2001-01-01 01:00:00
        2001-01-01 02:00:00
        2001-01-01 03:00:00
]
>>> date.dt.hour()
shape: (4,)
Series: '' [u32]
[
        0
        1
        2
        3
]