Extract week from underlying Date representation
Description
Returns the ISO week number starting from 1. The return value ranges from 1 to 53 (the last week of year differs across years).
Usage
<Expr>$dt$week()
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(
week = pl$col("date")$dt$week()
)
#> shape: (12, 2)
#> ┌────────────┬──────┐
#> │ date ┆ week │
#> │ --- ┆ --- │
#> │ date ┆ i8 │
#> ╞════════════╪══════╡
#> │ 2020-12-25 ┆ 52 │
#> │ 2020-12-26 ┆ 52 │
#> │ 2020-12-27 ┆ 52 │
#> │ 2020-12-28 ┆ 53 │
#> │ 2020-12-29 ┆ 53 │
#> │ … ┆ … │
#> │ 2021-01-01 ┆ 53 │
#> │ 2021-01-02 ┆ 53 │
#> │ 2021-01-03 ┆ 53 │
#> │ 2021-01-04 ┆ 1 │
#> │ 2021-01-05 ┆ 1 │
#> └────────────┴──────┘