daft.Expression.dt.month

daft.Expression.dt.month#

Expression.dt.month() Expression[source]#

Retrieves the month for a datetime column

Example

>>> import daft, datetime
>>> df = daft.from_pydict({
...         "datetime": [
...             datetime.datetime(2024, 7, 3, 0, 0, 0),
...             datetime.datetime(2024, 6, 4, 0, 0, 0),
...             datetime.datetime(2024, 5, 5, 0, 0, 0),
...         ],
...     }
... )
>>> df.with_column("month", df["datetime"].dt.month()).collect()
╭───────────────────────────────┬────────╮
│ datetime                      ┆ month  │
│ ---                           ┆ ---    │
│ Timestamp(Microseconds, None) ┆ UInt32 │
╞═══════════════════════════════╪════════╡
│ 2024-07-03 00:00:00           ┆ 7      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2024-06-04 00:00:00           ┆ 6      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2024-05-05 00:00:00           ┆ 5      │
╰───────────────────────────────┴────────╯

(Showing first 3 of 3 rows)
Returns:

a UInt32 expression with just the month extracted from a datetime column

Return type:

Expression