我正在尝试通过不同框架中包含的名称对 rust-polars 数据框进行子集化:
use polars::prelude::*;
fn main() {
let mut df = df! [
"names" => ["a", "b", "c", "d"],
"values" => [1, 2, 3, 4],
"floats" => [1.25, 2., 1., 0.5]
].unwrap();
// println!("{:?}", df);
let mut df1 = df! [
"names" => ["b", "c"],
"values" => [2, 3]
].unwrap();
// println!("original df: {:?}", df1);
let df2 = df
.lazy()
.filter(col("names").is_in(df1.column("names")))
.collect()
.unwrap();
// println!("{:?}", df2);
}
这会导致出现错误消息:
error[E0599]: no method named `is_in` found for enum `Expr` in the current scope
--> src/main.rs:22:30
|
22 | .filter(col("names").is_in(df1.column("names")))
| ^^^^^
|
help: there is a method `is_finite` with a similar name, but with different arguments
--> /home/puller/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/dsl/mod.rs:781:5
|
781 | pub fn is_finite(self) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0599`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
此页面建议is_in
“仅在 crate 功能 polars-ops 上可用”。但是,将“polars-ops”添加到我的 Cargo.toml 并没有帮助:
[dependencies]
polars = {version = "0.46.0", features = ["lazy", "polars-ops"]}
此外,的签名似乎与本问题is_in
中讨论的签名不同。因此,尚不清楚该功能是否已被贬值或可从另一个板条箱或其他东西中获得。
我也试过
let df2 = df
.lazy()
.filter(is_in(col("names"), df1.column("names")))
.collect()
.unwrap();
println!("{:?}", df2);
在这种情况下,错误信息是
error[E0425]: cannot find function `is_in` in this scope
--> src/main.rs:30:17
|
30 | .filter(is_in(col("names"), df1.column("names")))
| ^^^^^ not found in this scope
For more information about this error, try `rustc --explain E0425`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
更新
仔细查看之前链接的威胁,正确的签名是这个,来自 crate is_in
。错误消息是 no
error[E0277]: the trait bound `Expr: From<&polars::prelude::Column>` is not satisfied
--> src/main.rs:19:36
|
19 | .filter(col("names").is_in(df1.column("names").unwrap()))
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&polars::prelude::Column>` is not implemented for `Expr`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
`Expr` implements `From<&str>`
`Expr` implements `From<AggExpr>`
`Expr` implements `From<bool>`
`Expr` implements `From<f32>`
`Expr` implements `From<f64>`
`Expr` implements `From<i16>`
`Expr` implements `From<i32>`
`Expr` implements `From<i64>`
and 3 others
= note: required for `&polars::prelude::Column` to implement `Into<Expr>`
note: required by a bound in `polars_plan::dsl::<impl Expr>::is_in`
--> /home/puller/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/dsl/mod.rs:1190:21
|
1190 | pub fn is_in<E: Into<Expr>>(self, other: E) -> Self {
| ^^^^^^^^^^ required by this bound in `polars_plan::dsl::<impl Expr>::is_in`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
您可以这样做。为了编译它,您必须在文件
is_in
中启用该功能。这里使用从创建表达式。这是因为要求它的参数是表达式类型。Cargo.toml
lit
Series
is_in