如何从 Polars Series 或 ChunkedArray 获取 Vec?

Hak*_*ase 3 rust rust-polars

在 Rust Polars 中,如何将 aSeries或转换ChunkedArray为 a Vec

rit*_*e46 6

您可以collect将值转换为Vec.

use polars::prelude::*;

fn main() -> Result<()> {
    let s = Series::new("a", 0..10i32);

    let as_vec: Vec<Option<i32>> = s.i32()?.into_iter().collect();

    // if we are certain we don't have missing values
    let as_vec: Vec<i32> = s.i32()?.into_no_null_iter().collect();
    Ok(())
}
Run Code Online (Sandbox Code Playgroud)

  • 好的,我发现[这里](https://pola-rs.github.io/polars/polars/docs/eager/index.html) 对于 str 值,将 ```i32()``` 替换为 ``` utf8()```! (2认同)