'Can any one provide example related to polars as_struct().apply()
I try to add array column to the existing data-frame. input is something like this
| 1 | 3 |
| 2 | 4 |
and output is
| 1 | 3 | [?, ?, ?, ?] |
| 2 | 4 | [?, ?, ?, ?] |
value of the array will be populated by some custom function.
I try to implement something like this.
let df = df![
"a" => [1, 2],
"b" => [3, 4]
]?;
let lf: LazyFrame = df.lazy().select(
as_struct(&[col("a"), col("b")]).apply(
somefn,
GetOutput::from_type(DataType::List(Box::new(DataType::Float32))),
));
I don't know how to implement this somefn.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
