

- 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 # 输出查看
