I am using Rust with cargo 1.80.1
and polars = "0.42.0"
, and I want to convert a polars Series of Strings to Vec<String>
as more common type, which is to be used by my other functions without polars. For additional information, in Python pandas.Series
, it is like this: ds.to_list()
.
I am a beginner to Rust and I could not find a solution. Here are similar posts but not help with my case.
- How to convert a Series of Strings into an Array or Vec of Strings. It involves something about
.lit()
and the comments suggestgroup_by()
. Irrelevant to my question. - How to get a Vec from polars Series or ChunkedArray?. It is about a Series of numbers, not of strings. One of their command suggests
.utf8()
, but I tried, this method is not available (anymore). And I cannot find anything aboututf8()
on https://docs.pola.rs, for the current version.
use polars::prelude::*;
fn my_func() -> Vec<String> {
let ds: Series = Series::new("name", &vec!["apple", "orange", "banana"]);
// Convert s to Vec<String>
let result: Vec<String> = ds.str().unwrap(); // Not working, res type is &ChunkedArray<StringType>
result // It should be a vector of ["apple", "orange", "banana"].
}
Can anyone please help me? Thanks!
9