【问题标题】:List of structs in (Rust) Polars column(Rust) Polars 列中的结构列表
【发布时间】:2022-09-23 02:10:22
【问题描述】:

假设我有一个 list[list[str]] 类型的 Polars 列:

Foos
---
list[list[str]]

[[\"a\", \"b\"], [\"c\", \"d\"], [\"e\", \"f\"]]
[[\"g\", \"h\"], [\"i\", \"j\"], [\"k\", \"l\"]]
[[\"m\", \"n\"], [\"o\", \"p\"], [\"q\", \"r\"]]
...

和一个结构Foo

struct Foo {
    f1: &str,
    f2: &str,
}

如何获得系列list[Foo]

Foos
---
list[Foo]

[Foo { f1: \"a\", f2: \"b\" }, Foo { f1: \"c\", f2: \"d\" }, Foo { f1: \"e\", f2: \"f\" }]
[Foo { f1: \"g\", f2: \"h\" }, Foo { f1: \"i\", f2: \"j\" }, Foo { f1: \"k\", f2: \"l\" }]
[Foo { f1: \"m\", f2: \"n\" }, Foo { f1: \"o\", f2: \"p\" }, Foo { f1: \"q\", f2: \"r\" }]

我尝试过:

  • ChunkedArray<ObjectType<T>>
  • StructArray<Struct> 字段定义为:
let fields = vec![
    polars::prelude::ArrowField::new(\"first_name\", polars::prelude::ArrowDataType::Utf8, false),
    polars::prelude::ArrowField::new(\"last_name\", polars::prelude::ArrowDataType::Utf8, false),
];

无济于事。 这是可能吗?

    标签: rust rust-polars


    【解决方案1】:

    单行示例:

    let foo = StructChunked::new("foo", 
        &[
            Series::new("f1", ["a", "c", "e"]),
            Series::new("f2", ["b", "d", "f"]),
        ]).unwrap();
    let new_authors = new_authors.into_series();
    
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 2023-01-28
      • 2022-12-18
      • 2022-01-11
      • 2022-10-16
      • 2023-01-10
      • 2023-01-03
      • 2022-12-21
      • 1970-01-01
      相关资源
      最近更新 更多