我正在使用带有 python 2.7 的 dask dataframe,并希望从我的 df 中删除重复的索引值。
当使用 pandas 时,我会使用
df = df[~df.index.duplicated(keep = "first")]
而且它有效
当尝试对 dask dataframe 执行相同操作时,我得到
AttributeError: 'Index' object has no attribute 'duplicated'
我可以重置索引,然后使用作为索引的列来删除重复项,但如果可能的话我想避免它
我可以使用 df.compute() 并删除重复的索引值,但这个 df 对于内存来说太大了。
如何使用 dask 数据帧从数据帧中删除重复的索引值?
最佳答案
我认为您需要将 index
转换为 Series
by to_series
, keep='first'
应该省略,因为 duplicated
中的默认参数:
df = df[~df.index.to_series().duplicated()]
关于python - dask dataframe 删除重复的索引值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47534099/