Extract weekday from underlying Date representation
Description
Returns the ISO weekday number where Monday = 1 and Sunday = 7.
Usage
<Expr>$dt$weekday()
Value
A polars expression
Examples
library("polars")
df <- pl$select(
date = pl$date_range(
as.Date("2020-12-25"),
as.Date("2021-1-05"),
interval = "1d"
)
)
df$with_columns(
weekday = pl$col("date")$dt$weekday()
)
#> shape: (12, 2)
#> ┌────────────┬─────────┐
#> │ date ┆ weekday │
#> │ --- ┆ --- │
#> │ date ┆ i8 │
#> ╞════════════╪═════════╡
#> │ 2020-12-25 ┆ 5 │
#> │ 2020-12-26 ┆ 6 │
#> │ 2020-12-27 ┆ 7 │
#> │ 2020-12-28 ┆ 1 │
#> │ 2020-12-29 ┆ 2 │
#> │ … ┆ … │
#> │ 2021-01-01 ┆ 5 │
#> │ 2021-01-02 ┆ 6 │
#> │ 2021-01-03 ┆ 7 │
#> │ 2021-01-04 ┆ 1 │
#> │ 2021-01-05 ┆ 2 │
#> └────────────┴─────────┘