【发布时间】:2017-12-29 11:43:28
【问题描述】:
我刚刚看了几个帖子,但我没有找到解决方案。
我正在尝试使用 Python 中的 Pandas 比较不同工作簿中的 2 个 Excel 文件。
工作1:
A B C
1 1 1
2 2 2
3 3 3
工作2:
A B C
1 1 1
2 5 2
3 3 3
希望输出:
A B C
1 1 1
3 3 3
到目前为止,我得到的是:
import pandas as pd
df1 = pd.read_excel('/path/work1.xlsx')
df2 = pd.read_excel('/path/work2.xlsx')
common = df1[df1==df2]
print common
common.to_excel('/path/result.xlsx')
但我得到的是:
A B C
1 1 1
2 2
3 3 3
重点是,如果work1的B列和work2有任何重合,那么输出应该只有整行重合。
我正在使用 NGS 变异注释,因此有助于分析共享变异的受影响家族。
【问题讨论】:
标签: python pandas dataframe compare