polars.LazyFrame.__getitem__#

LazyFrame.__getitem__(item: slice) LazyFrame[source]#

Support slice syntax, returning a new LazyFrame.

All other forms of subscripting are currently unsupported here; use select, filter, or other standard methods instead.

Notes

LazyFrame is designed primarily for efficient computation and does not know its own length so, unlike DataFrame, certain slice patterns (such as those requiring negative stop/step) may not be supported.

Examples

>>> lf = pl.LazyFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
>>> lf[:2].collect()
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 4   │
│ 2   ┆ 5   │
└─────┴─────┘
>>> lf[::2].collect()
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 4   │
│ 3   ┆ 6   │
└─────┴─────┘