daft.Expression.dt.day_of_week

daft.Expression.dt.day_of_week#

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

Retrieves the day of the week for a datetime column, starting at 0 for Monday and ending at 6 for Sunday

Example

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

(Showing first 3 of 3 rows)
Returns:

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

Return type:

Expression