【问题标题】:Get the unique row by comparing the two dataframes [duplicate]通过比较两个数据框来获取唯一行[重复]
【发布时间】:2020-04-11 16:50:34
【问题描述】:

有两个df

df1

0       1 
1234   mark
4865   john
4866   joseph
7916   stuart

df2

0       1       2  
1234   mark    test1
4865   john    test2
4866   joseph  test3

预期输出:

从两个数据框中获取唯一行比较并在 df1 中显示唯一列

df1

0       1
7916   stuart 

【问题讨论】:

  • 你有没有尝试过?
  • 显示df1中的唯一列”是什么意思? df1 只有一列。
  • 尝试合并,外部但当 df1 的某些行与 df2 匹配时,我需要从 df1 中删除行
  • 这能回答你的问题吗? pandas get rows which are NOT in other dataframe

标签: python pandas dataframe


【解决方案1】:

你可以尝试如下

df1[(~df1['0'].isin(df2['0'])) & (~df1['1'].isin(df2['1']))]
      0     1
3   7916    stuart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 2019-12-20
    • 2023-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多