简体   繁体   English

从DataFrame视图中删除重复项

[英]Remove duplicates from DataFrame view

I have code similar to this: 我有与此类似的代码:

df = raw_report[some_columns].copy()
df.drop_duplicates(inplace=True)

I used copy() to avoid a warning about uncertainty wrt view / copy. 我使用copy()来避免关于不确定性的警告。 However, I'd like to use a view, because later I only read from this DataFrame . 但是,我想使用一个视图,因为稍后我仅从此DataFrame读取。 The line that generated the warning was the line that removes duplicates, so I assume it doesn't generate a view. 生成警告的行是删除重复项的行,因此我认为它不会生成视图。

Thus, my question: is there a way to remove duplicates from the view? 因此,我的问题是:有没有办法从视图中删除重复项? Or, rather, is there a way to refine a view such that it doesn't contain duplicates? 或者,是否有一种方法可以细化视图,使其不包含重复项?

我认为您只需要通过DataFrame.drop_duplicates某些列来放置重复项的参数子集:

raw_report.drop_duplicates(subset=[some_columns],inplace=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM