polars.int_range
-
Generate a range of integers.
- 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
-
Data type of the range.
- eager
-
Evaluate immediately and return a
Series. If set toFalse(default), return an expression instead.
- Returns:
-
- Expr or Series
-
Column of integer data type
dtype.
See also
-
int_ranges -
Generate a range of integers for each row of the input columns.
Examples
>>> pl.int_range(0, 3, eager=True) shape: (3,) Series: 'literal' [i64] [ 0 1 2 ]endcan be omitted for a shorter syntax.>>> pl.int_range(3, eager=True) shape: (3,) Series: 'literal' [i64] [ 0 1 2 ]Generate an index column by using
int_rangein conjunction withlen().>>> df = pl.DataFrame({"a": [1, 3, 5], "b": [2, 4, 6]}) >>> df.select( ... pl.int_range(pl.len(), dtype=pl.UInt32).alias("index"), ... pl.all(), ... ) shape: (3, 3) ┌───────┬─────┬─────┐ │ index ┆ a ┆ b │ │ --- ┆ --- ┆ --- │ │ u32 ┆ i64 ┆ i64 │ ╞═══════╪═════╪═════╡ │ 0 ┆ 1 ┆ 2 │ │ 1 ┆ 3 ┆ 4 │ │ 2 ┆ 5 ┆ 6 │ └───────┴─────┴─────┘
polars.int_range(
start: int | IntoExprColumn = 0,
end: int | IntoExprColumn | None = None,
step: int = 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_range.html