“在 Polars Rust 中删除重复项”

huangapple go评论142阅读模式
英文:

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(
    &amp;self,
    subset: Option&lt;&amp;[String]&gt;,
    keep: UniqueKeepStrategy,
    slice: Option&lt;(i64, usize)&gt;
) -&gt; PolarsResult&lt;DataFrame&gt;

but somehow when i executed :

fn main() -&gt; Result&lt;(), Box&lt;dyn Error&gt;&gt; {
    let col_name = String::from(&quot;time&quot;);
    let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
    println!(&quot;{:?}&quot;, df);
    Ok(())
}

i got this error:

error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
   --&gt; 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可以简单地是&#39;None&#39;

另外:使用unique_stable来避免顺序混乱。

英文:

the enum should be UniqueKeepStrategy, and the slice could be simply &#39;None&#39;

also: use unique_stable instead to avoid order being meseed up.

huangapple
  • 本文由 发表于 2023年6月8日 09:11:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定