Retrieves the day of the week for a datetime column, starting at 0 for Monday and ending at 6 for Sunday.
Returns:
| Name | Type | Description |
Expression | Expression | a UInt32 expression with just the day_of_week extracted from a datetime column |
Examples:
1
2
3
4
5
6
7
8
9
10
11
12
13 | >>> import datetime
>>> import daft
>>> from daft.functions import day_of_week
>>> 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", day_of_week(df["datetime"])).collect()
|
╭─────────────────────┬─────────────╮
│ datetime ┆ day_of_week │
│ --- ┆ --- │
│ Timestamp[us] ┆ 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)
Source code in daft/functions/datetime.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541 | def day_of_week(expr: Expression) -> Expression:
"""Retrieves the day of the week for a datetime column, starting at 0 for Monday and ending at 6 for Sunday.
Returns:
Expression: a UInt32 expression with just the day_of_week extracted from a datetime column
Examples:
>>> import datetime
>>> import daft
>>> from daft.functions import day_of_week
>>> 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", day_of_week(df["datetime"])).collect()
╭─────────────────────┬─────────────╮
│ datetime ┆ day_of_week │
│ --- ┆ --- │
│ Timestamp[us] ┆ UInt32 │
╞═════════════════════╪═════════════╡
│ 2024-07-03 00:00:00 ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2024-07-04 00:00:00 ┆ 3 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2024-07-05 00:00:00 ┆ 4 │
╰─────────────────────┴─────────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("day_of_week", expr)
|