原文:https://blog.csdn.net/weixin_40508682/article/details/90666748
Excel的合并:
import pandas as pd
import os
excel_dir = 'D:Program Files (x86)GeanycodeCode-Commonexcel'
os.chdir(excel_dir)
li = []
for i in os.listdir(excel_dir):
li.append(pd.read_excel(i))
print('已合并'+i)
# 合并完成后的excel,是放在excel文件夹下的
writer = pd.ExcelWriter('test.xlsx')
pd.concat(li).to_excel(writer,'sheet1',index=False)
writer.save()
print('合并完成')
Excel 去重
import pandas as pd
frame = pd.read_excel('test.xlsx')
data = pd.DataFrame(frame)
data.drop_duplicates(['标题链接'], keep='first', inplace=True)
# drop_duplicates用法:subset=‘需要去重复的列名’,keep=‘遇到重复的时保留第一个还是保留最后一个’,inplace=‘去除重复项,还是保留重复项的副本’
data.to_excel('out.xlsx')
print('合并完成')