我有两个数据帧,我正在尝试输出其中一个数据帧中的数据,而不是另一个数据帧中的数据。
我可以使用第一个数据帧中的数据,但不能使用第二个数据帧中的数据
only_new = old.merge(
new, 'outer', on=['Employee ID', 'Benefit Plan Type'],
suffixes=['','_'], indicator=True
).query('_merge == "left_only"').reindex_axis(old.columns, axis=1)
这是我用来获取仅在第二个数据框中的数据的方法
only_new =new.merge(
old, 'outer', on=['Employee ID', 'Benefit Plan Type'],
suffixes=['','_'], indicator=True
).query('_merge == "left only"').reindex_axis(new.columns, axis=1)
但它不返回任何数据,但使用 Excel 我可以看到应该有几行。
看来这应该可行
only_new = old.merge(new, on='Employee ID', indicator=True, how='outer',
only_new[only_new['_merge'] == 'right_only'])
但我得到
SyntaxError: non-keyword arg after keyword arg