删除Python Pandas中的所有重复行 [英] Drop all duplicate rows in Python Pandas

查看:931
本文介绍了删除Python Pandas中的所有重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c code code code code code函数非常适合统一一个数据框。但是,要传递的关键字参数之一是 take_last = True take_last = False ,而我想放弃所有行都跨越一列子集重复。这是可能吗?

The pandas drop_duplicates function is great for "uniquifying" a dataframe. However, one of the keyword arguments to pass is take_last=True or take_last=False, while I would like to drop all rows which are duplicates across a subset of columns. Is this possible?

    A   B   C
0   foo 0   A
1   foo 1   A
2   foo 1   B
3   bar 1   A

作为一个例子,我想删除行它们匹配列 A C ,因此应该删除行0和1。

As an example, I would like to drop rows which match on columns A and C so this should drop rows 0 and 1.

推荐答案

现在使用 drop_duplicates 和保留参数。

import pandas as pd
df = pd.DataFrame({"A":["foo", "foo", "foo", "bar"], "B":[0,1,1,1], "C":["A","A","B","A"]})
df.drop_duplicates(subset=['A', 'C'], keep=False)

这篇关于删除Python Pandas中的所有重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆