“在 Polars Rust 中删除重复项”

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

remove duplicates in polars rust

问题

我正在尝试在我的数据框中基于“time”列删除重复项。

我阅读了官方文档,其中定义了unique()方法如下:

  1. pub fn unique(
  2. &self,
  3. subset: Option<&[String]>,
  4. keep: UniqueKeepStrategy,
  5. slice: Option<(i64, usize)>
  6. ) -> PolarsResult<DataFrame>

但是不知何故,当我执行以下代码时:

  1. fn main() -> Result<(), Box<dyn Error>> {
  2. let col_name = String::from("time");
  3. let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
  4. println!("{:?}", df);
  5. Ok(())
  6. }

我收到了以下错误:

  1. error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
  2. --> src/main.rs:155:49
  3. |
  4. 155 | let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
  5. | ^^^^^^^^^^ use of undeclared type `UniqueKeep`

这可能是某种缺少导入吗?
我只加载了预导入:

  1. 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:

  1. pub fn unique(
  2. &amp;self,
  3. subset: Option&lt;&amp;[String]&gt;,
  4. keep: UniqueKeepStrategy,
  5. slice: Option&lt;(i64, usize)&gt;
  6. ) -&gt; PolarsResult&lt;DataFrame&gt;

but somehow when i executed :

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

i got this error:

  1. error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
  2. --&gt; src/main.rs:155:49
  3. |
  4. 155 | let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
  5. | ^^^^^^^^^^ use of undeclared type `UniqueKeep`

could it be some kind of missing import?
i only loaded the prelude:

  1. 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:

确定