polars.internals.series.datetime.DateTimeNameSpace.week#

DateTimeNameSpace.week() Series[source]#

Extract the week from the underlying date representation.

Applies to Date and Datetime columns.

Returns the ISO week number starting from 1. The return value ranges from 1 to 53. (The last week of year differs by years.)

Returns:
Week number as UInt32

Examples

>>> from datetime import datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2001, 4, 1)
>>> date = pl.date_range(start, stop, interval="1mo")
>>> date
shape: (4,)
Series: '' [datetime[μs]]
[
        2001-01-01 00:00:00
        2001-02-01 00:00:00
        2001-03-01 00:00:00
        2001-04-01 00:00:00
]
>>> date.dt.week()
shape: (4,)
Series: '' [u32]
[
        1
        5
        9
        13
]