首页 > 解决方案 > Pandas Drop 部分重复

问题描述

我有 2 个 dfs:

df1:

    x  y  z
0   1  2  r
1   a  c  2
2  22  g  d

df2:

    x  y  z
0   1  2  r
1   a  b  2
2   3  g  d

我想在列yz重复时删除。

期望的结果:

        x  y  z
    1   a  c  2

因为 df1 和 df2 在列中都有相同的值y并且z

标签: pythonpandas

解决方案


 cols=['y','z']#columns to check for having same value
 df1[~(df1[cols]==df2[cols]).all(axis=1)]#extracting the rows where x and y are `not equal(~)` in both dataframes

推荐阅读