我试图理解两极的两种模式(懒惰,渴望)。我找到了一种懒惰的方法:
let out = df
.lazy()
.select([col("A"), col("B")
.filter(col("B").str().contains(input))])
.collect()
.unwrap().head(Some(10));
但如何急切地做到这一点呢?有一个例子:
https://docs.rs/polars/latest/polars/docs/eager/index.html#filter,我无法使用str().contains()。我是否正确地理解了col("")是特定于懒惰的,列(“”)是针对急切的?
// create a mask to filter out null values
let mask = df.column("sepal.width")?.is_not_null();
// apply the filter on a DataFrame
let filtered_df = df.filter(&mask)?;
发布于 2022-11-03 15:33:29
在Series
上,方法不像Expr
上的那样称为str
,而是utf8
(参见https://docs.rs/polars/latest/polars/series/struct.Series.html#method.utf8)。在你的例子中,你会像这样使用它:
let filtered_df = df.filter(&df.column("B")?.utf8()?.contains(input)?)?;
注意,?
操作符有多种用途,这要求您的函数返回兼容的Result
(例如PolarsResult
)。
https://stackoverflow.com/questions/74308686
复制相似问题