polars.Expr.dt.iso_year#

Expr.dt.iso_year() Expr[source]#

Extract ISO year from underlying Date representation.

Applies to Date and Datetime columns.

Returns the year number in the ISO standard. This may not correspond with the calendar year.

Returns:
Expr

Expression of data type Int32.

Examples

>>> from datetime import timedelta, datetime
>>> start = datetime(2001, 1, 1)
>>> stop = datetime(2006, 1, 1)
>>> df = pl.DataFrame(
...     {"date": pl.date_range(start, stop, timedelta(days=180), eager=True)}
... )
>>> df.select(
...     [
...         pl.col("date"),
...         pl.col("date").dt.iso_year().alias("iso_year"),
...     ]
... )
shape: (11, 2)
┌─────────────────────┬──────────┐
│ date                ┆ iso_year │
│ ---                 ┆ ---      │
│ datetime[μs]        ┆ i32      │
╞═════════════════════╪══════════╡
│ 2001-01-01 00:00:00 ┆ 2001     │
│ 2001-06-30 00:00:00 ┆ 2001     │
│ 2001-12-27 00:00:00 ┆ 2001     │
│ 2002-06-25 00:00:00 ┆ 2002     │
│ …                   ┆ …        │
│ 2004-06-14 00:00:00 ┆ 2004     │
│ 2004-12-11 00:00:00 ┆ 2004     │
│ 2005-06-09 00:00:00 ┆ 2005     │
│ 2005-12-06 00:00:00 ┆ 2005     │
└─────────────────────┴──────────┘