polars.int_ranges
-
Generate a range of integers for each row of the input columns.
- Parameters:
-
- start
-
Start of the range (inclusive). Defaults to 0.
- end
-
End of the range (exclusive). If set to
None(default), the value ofstartis used andstartis set to0. - step
-
Step size of the range.
- dtype
-
Integer data type of the ranges. Defaults to
Int64. - eager
-
Evaluate immediately and return a
Series. If set toFalse(default), return an expression instead.
- Returns:
-
- Expr or Series
-
Column of data type
List(dtype).
See also
-
int_range -
Generate a single range of integers.
Examples
>>> df = pl.DataFrame({"start": [1, -1], "end": [3, 2]}) >>> df.with_columns(int_range=pl.int_ranges("start", "end")) shape: (2, 3) ┌───────┬─────┬────────────┐ │ start ┆ end ┆ int_range │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ list[i64] │ ╞═══════╪═════╪════════════╡ │ 1 ┆ 3 ┆ [1, 2] │ │ -1 ┆ 2 ┆ [-1, 0, 1] │ └───────┴─────┴────────────┘endcan be omitted for a shorter syntax.>>> df.select("end", int_range=pl.int_ranges("end")) shape: (2, 2) ┌─────┬───────────┐ │ end ┆ int_range │ │ --- ┆ --- │ │ i64 ┆ list[i64] │ ╞═════╪═══════════╡ │ 3 ┆ [0, 1, 2] │ │ 2 ┆ [0, 1] │ └─────┴───────────┘
polars.int_ranges(
start: int | IntoExprColumn = 0,
end: int | IntoExprColumn | None = None,
step: int | IntoExprColumn = 1,
*,
dtype: PolarsIntegerType | DataTypeExpr = Int64,
eager: bool = False,
) → Expr | Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.int_ranges.html