daft.Expression.dt.year#
- Expression.dt.year() Expression [source]#
Retrieves the year for a datetime column
Example
>>> import daft, datetime >>> df = daft.from_pydict({ ... "datetime": [ ... datetime.datetime(2024, 7, 3, 0, 0, 0), ... datetime.datetime(2023, 7, 4, 0, 0, 0), ... datetime.datetime(2022, 7, 5, 0, 0, 0), ... ], ... } ... ) >>> df.with_column("year", df["datetime"].dt.year()).collect() ╭───────────────────────────────┬───────╮ │ datetime ┆ year │ │ --- ┆ --- │ │ Timestamp(Microseconds, None) ┆ Int32 │ ╞═══════════════════════════════╪═══════╡ │ 2024-07-03 00:00:00 ┆ 2024 │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 2023-07-04 00:00:00 ┆ 2023 │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 2022-07-05 00:00:00 ┆ 2022 │ ╰───────────────────────────────┴───────╯ (Showing first 3 of 3 rows)
- Returns:
a UInt32 expression with just the year extracted from a datetime column
- Return type:
Expression