polars.internals.series.datetime.DateTimeNameSpace.year#

DateTimeNameSpace.year() Series[source]#

Extract the year from the underlying date representation.

Applies to Date and Datetime columns.

Returns the year number in the calendar date.

Returns:
Year part as Int32

Examples

>>> from datetime import datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2002, 1, 1)
>>> date = pl.date_range(start, stop, interval="1y")
>>> date
shape: (2,)
Series: '' [datetime[μs]]
[
        2001-01-01 00:00:00
        2002-01-01 00:00:00
]
>>> date.dt.year()
shape: (2,)
Series: '' [i32]
[
        2001
        2002
]