import polars as pl
import turtle_island as ti
= pl.DataFrame({"a": [1, 3, 5], "b": [2, 4, 6]})
df all()) df.select(ti.make_index(), pl.
shape: (3, 3)
index | a | b |
---|---|---|
u32 | i64 | i64 |
0 | 1 | 2 |
1 | 3 | 4 |
2 | 5 | 6 |
Returns a Polars expression that creates a virtual row index.
Borrowed from the Polars documentation and adapted for expression-level use.
Unlike pl.DataFrame.with_row_index(), which works at the DataFrame level, this expression can be composed inline and reused without materializing an actual column.
offset : int = 0
Start the index at this offset. Cannot be negative.
name : str = 'index'
The name of the resulting column.
: pl.Expr
A Polars expression that yields a sequential integer index starting from 0.
Adds a sequential index column to the DataFrame: