[英]Drop rows when rows have same values in different order
I would like an efficient way to drop rows from a Pandas dataframe if rows have same values regardless of order如果行具有相同的值而不管顺序如何,我想要一种从 Pandas 数据框中删除行的有效方法
For example, this:例如,这个:
1 3
2 5
5 2
1 3
3 1
becomes:变成:
1 3
5 2
You could sort
the rows of a copy of the dataframe, drop_duplicates
and use the resulting indices to index the dataframe:您可以sort
数据帧副本drop_duplicates
的行进行sort
,并使用结果索引来索引数据帧:
df_ = df.copy()
df_.values.sort(1)
df = df.loc[df_.drop_duplicates().index, :]
# del df_
Output输出
col1 col2
0 1 3
1 2 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.