polars.LazyFrame.with_row_count
-
Add a column at index 0 that counts the rows.
Deprecated since version 0.20.4: Use the
with_row_index()method instead. Note that the default column name has changed from ‘row_nr’ to ‘index’.- Parameters:
-
- name
-
Name of the column to add.
- offset
-
Start the row count at this offset.
Warning
This can have a negative effect on query performance. This may, for instance, block predicate pushdown optimization.
Examples
>>> lf = pl.LazyFrame( ... { ... "a": [1, 3, 5], ... "b": [2, 4, 6], ... } ... ) >>> lf.with_row_count().collect() shape: (3, 3) ┌────────┬─────┬─────┐ │ row_nr ┆ a ┆ b │ │ --- ┆ --- ┆ --- │ │ u32 ┆ i64 ┆ i64 │ ╞════════╪═════╪═════╡ │ 0 ┆ 1 ┆ 2 │ │ 1 ┆ 3 ┆ 4 │ │ 2 ┆ 5 ┆ 6 │ └────────┴─────┴─────┘
LazyFrame.with_row_count(
name: str = 'row_nr',
offset: int = 0,
) → LazyFrame
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.with_row_count.html