Search code examples
rustrust-polars

Take every nth row on LazyFrame


I'm looking for the rust polars equivalent of the take_every function that is available for LazyFrames on python polars.

I want to determine the length of a LazyFrame and decimate it to less than n rows by skipping rows.


Solution

  • Series has take_every(), you can use it as follows:

    fn take_every(lazy_frame: LazyFrame, n: usize) -> LazyFrame {
        lazy_frame.select(&[col("*").map(move |s| Ok(Some(s.take_every(n))), GetOutput::same_type())])
    }