在 Polars 中,与 pandas 中的 drop_duplicates()
等价的函数是什么?
import polars as pl
df = pl.DataFrame({"a":[1,1,2], "b":[2,2,3], "c":[1,2,3]})
df
输出:
shape: (3, 3)
┌─────┬─────┬─────┐
│ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╡
│ 1 ┆ 2 ┆ 1 │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
│ 1 ┆ 2 ┆ 2 │
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
│ 2 ┆ 3 ┆ 3 │
└─────┴─────┴─────┘
代码:
df.drop_duplicates(["a", "b"])
出现以下错误:
属性错误:未找到drop_duplicates
df.distinct()
可以不带任何参数运行。看起来它只是为了回答这个问题而被包含进来的。Polars 有非常好的文档字符串,运行help(df.distinct)
或help(df.[method])
来查找示例和默认参数。更多信息请参见 Polars Cookbook。 - Jenobi