polars.Expr.dt.hour#
- Expr.dt.hour() Expr [source]#
Extract hour from underlying DateTime representation.
Applies to Datetime columns.
Returns the hour number from 0 to 23.
- Returns:
- Expr
Expression of data type
UInt32
.
Examples
>>> from datetime import timedelta, datetime >>> start = datetime(2001, 1, 1) >>> stop = datetime(2001, 1, 2) >>> df = pl.DataFrame( ... {"date": pl.date_range(start, stop, timedelta(hours=12), eager=True)} ... ) >>> df shape: (3, 1) ┌─────────────────────┐ │ date │ │ --- │ │ datetime[μs] │ ╞═════════════════════╡ │ 2001-01-01 00:00:00 │ │ 2001-01-01 12:00:00 │ │ 2001-01-02 00:00:00 │ └─────────────────────┘ >>> df.select(pl.col("date").dt.hour()) shape: (3, 1) ┌──────┐ │ date │ │ --- │ │ u32 │ ╞══════╡ │ 0 │ │ 12 │ │ 0 │ └──────┘