英文:
remove duplicates in polars rust
问题
我正在尝试在我的数据框中基于“time”列删除重复项。
我阅读了官方文档,其中定义了unique()
方法如下:
pub fn unique(
&self,
subset: Option<&[String]>,
keep: UniqueKeepStrategy,
slice: Option<(i64, usize)>
) -> PolarsResult<DataFrame>
但是不知何故,当我执行以下代码时:
fn main() -> Result<(), Box<dyn Error>> {
let col_name = String::from("time");
let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
println!("{:?}", df);
Ok(())
}
我收到了以下错误:
error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
--> src/main.rs:155:49
|
155 | let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
| ^^^^^^^^^^ use of undeclared type `UniqueKeep`
这可能是某种缺少导入吗?
我只加载了预导入:
use polars::prelude::*;
英文:
hi i am trying to remove duplicates based on a column "time" in my dataframe.
i read the official document which defines the unique() method as follows:
pub fn unique(
&self,
subset: Option<&[String]>,
keep: UniqueKeepStrategy,
slice: Option<(i64, usize)>
) -> PolarsResult<DataFrame>
but somehow when i executed :
fn main() -> Result<(), Box<dyn Error>> {
let col_name = String::from("time");
let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
println!("{:?}", df);
Ok(())
}
i got this error:
error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
--> src/main.rs:155:49
|
155 | let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
| ^^^^^^^^^^ use of undeclared type `UniqueKeep`
could it be some kind of missing import?
i only loaded the prelude:
use polars::prelude::*;
答案1
得分: 1
枚举应该是UniqueKeepStrategy
,而slice
可以简单地是'None'
。
另外:使用unique_stable
来避免顺序混乱。
英文:
the enum should be UniqueKeepStrategy
, and the slice
could be simply 'None'
also: use unique_stable
instead to avoid order being meseed up.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论