polars.Expr.dt.quarter#
- Expr.dt.quarter() Expr [source]#
Extract quarter from underlying Date representation.
Applies to Date and Datetime columns.
Returns the quarter ranging from 1 to 4.
- Returns:
- Expr
Expression of data type
UInt32
.
Examples
>>> from datetime import timedelta, datetime >>> start = datetime(2001, 1, 1) >>> stop = datetime(2002, 6, 1) >>> df = pl.DataFrame( ... {"date": pl.date_range(start, stop, timedelta(days=180), eager=True)} ... ) >>> df shape: (3, 1) ┌─────────────────────┐ │ date │ │ --- │ │ datetime[μs] │ ╞═════════════════════╡ │ 2001-01-01 00:00:00 │ │ 2001-06-30 00:00:00 │ │ 2001-12-27 00:00:00 │ └─────────────────────┘ >>> df.select(pl.col("date").dt.quarter()) shape: (3, 1) ┌──────┐ │ date │ │ --- │ │ u32 │ ╞══════╡ │ 1 │ │ 2 │ │ 4 │ └──────┘