0

I have a DataFrame with a ListType column.

Now I am trying to find a way to process each list within that column.

If I could convert the list to a vector (ideally without unpacking the list and then re-packing it into a vector ... is there such a thing?) then I can do all kind of arithmetics on it.

With the ListType I do not know ... I looked at the docs but could not figure it out ...

use polars::chunked_array::builder::get_list_builder;
use polars::prelude::DataType::Float64;
use polars::prelude::*;

fn main() {
    let mut builder = get_list_builder(&DataType::Float64, 10, 10, "List Sample").unwrap();
    builder.append_series(&Series::new("", &[3.2, 3.7, 2.1, 2.5]));
    builder.append_series(&Series::new("", &[3.1, 2.5, 2.95]));
    builder.append_series(&Series::new("", &[1.8, 4.1]));
    let ca = builder.finish();

    let df = ca.into_series().into_frame();

    println!("DataFrame\t{:?}", df);

    // How to do arithmetic with values in the list?
    // E.g. get the CLOSEST_VALUE below 3.0 of a list ?

    // Ideally I would like to get a new Series with just the CLOSEST_VALUE below 3.0 of each list:

    /*

        Series: 'CLOSEST_VALUE below 3.0' [f64]
        [
           2.5
           2.95
           1.8
        ]

    */
}
Robert
  • 131
  • 1
  • 7

0 Answers0