polars.Series.dt.year#

Series.dt.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:
Series

Series of data type Int32.

Examples

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