【发布时间】:2023-03-12 14:12:01
【问题描述】:
我需要逐行比较两个不同大小的数据帧并打印出不匹配的行。让我们采取以下两个:
df1 = DataFrame({
'Buyer': ['Carl', 'Carl', 'Carl'],
'Quantity': [18, 3, 5, ]})
df2 = DataFrame({
'Buyer': ['Carl', 'Mark', 'Carl', 'Carl'],
'Quantity': [2, 1, 18, 5]})
在 df2 上逐行并打印出不在 df1 中的行的最有效方法是什么,例如
Buyer Quantity
Carl 2
Mark 1
重要提示:我不想排:
Buyer Quantity
Carl 3
包含在差异中:
我已经尝试过: Comparing two dataframes of different length row by row and adding columns for each row with equal value 和Compare two DataFrames and output their differences side-by-side
但是这些不符合我的问题。
【问题讨论】:
标签: python pandas dataframe diff