Skip to content

Extract quarter from underlying Date representation

Description

Returns the quarter ranging from 1 to 4.

Usage

<Expr>$dt$quarter()

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(
  quarter = pl$col("date")$dt$quarter()
)
#> shape: (12, 2)
#> ┌────────────┬─────────┐
#> │ date       ┆ quarter │
#> │ ---        ┆ ---     │
#> │ date       ┆ i8      │
#> ╞════════════╪═════════╡
#> │ 2020-12-25 ┆ 4       │
#> │ 2020-12-26 ┆ 4       │
#> │ 2020-12-27 ┆ 4       │
#> │ 2020-12-28 ┆ 4       │
#> │ 2020-12-29 ┆ 4       │
#> │ …          ┆ …       │
#> │ 2021-01-01 ┆ 1       │
#> │ 2021-01-02 ┆ 1       │
#> │ 2021-01-03 ┆ 1       │
#> │ 2021-01-04 ┆ 1       │
#> │ 2021-01-05 ┆ 1       │
#> └────────────┴─────────┘