Skip to content

Take every nth row in the LazyFrame

Source code

Description

Take every nth row in the LazyFrame

Usage

<LazyFrame>$gather_every(n, offset = 0)

Arguments

n Gather every n-th row.
offset Starting index.

Value

A LazyFrame

Examples

library("polars")

lf = pl$LazyFrame(a = 1:4, b = 5:8)
lf$gather_every(2)$collect()
#> shape: (2, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 1   ┆ 5   │
#> │ 3   ┆ 7   │
#> └─────┴─────┘
lf$gather_every(2, offset = 1)$collect()
#> shape: (2, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 2   ┆ 6   │
#> │ 4   ┆ 8   │
#> └─────┴─────┘