Demo示例:
现有两个Excel表格,SKU不同,需要找出不同之处

代码结果演示:

代码:
import pandas
test1_path = r'C:\Users\Administrator\Desktop\新建文件夹 (2)\test1.xlsx'
test2_path = r'C:\Users\Administrator\Desktop\新建文件夹 (2)\test2.xlsx'
result_path = r'C:\Users\Administrator\Desktop\新建文件夹 (2)\result.xlsx'
test1_doc = pandas.read_excel(test1_path) # 读取文件
test2_doc = pandas.read_excel(test2_path) # 读取文件
test1_doc['File_name'] = 'test1' # 增加一列 文件名
test2_doc['File_name'] = 'test2' # 增加一列 文件名
doc = pandas.merge(test1_doc,test2_doc,on='sku',how='outer') # merge 合并查询
result = doc.where(doc.notna(),'-') # 替换 NaN 为 -
result.to_excel(result_path,index=None) # 导出文件 不添加索引
result # 输出查看
导出结果:result表格













![文件上传 [极客大挑战 2019]Upload 1](https://img-blog.csdnimg.cn/64af20746c5d4c668cc14abd67b49c47.png)






