我正在学习Rust,并决定使用Polars框架,并得到一些我无法理解的错误.这段代码只是为了创建一个嵌套框架,然后添加一个新列作为两个现有列的总和:
fn main() {
let _df = DataFrame::default();
let df= df!(
"a" => &[1, 2, 3, 4],
"b" => &[2, 3, 4, 5],
);
println!("{:#?}", df);
let df = df.lazy()
.with_column(
col("a") + col("b"),
"c"
)
.collect()
.unwrap();
}
它在调用lazy()
方法时失败:
error[E0599]: no method named `lazy` found for enum `Result` in the current scope
--> src/bin/dataframes.rs:16:17
|
16 | let df = df.lazy()
| ^^^^ method not found in `Result<DataFrame, PolarsError>`
|
note: the method `lazy` exists on the type `polars::prelude::DataFrame`
--> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-lazy-0.35.4/src/frame/mod.rs:45:5
|
45 | fn lazy(self) -> LazyFrame;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using `Result::expect` to unwrap the `polars::prelude::DataFrame` value, panicking if the value is a `Result::Err`
我看到编译器给了我一些可能有用的建议,但我不知道如何或在哪里使用Result::expect
来解包Dataframe值.
我知道out
可能是一个DataFrame或一个错误,所以我需要在这里添加一些match
构造吗?
EDIT个 好吧,我知道该怎么做了,但我很困惑,因为我在官方文档中没有看到任何这一点:
let df = df.expect("").lazy()
.with_column(
(col("a") + col("b")).alias("c")
)
.collect()
.unwrap();