python匹配两个excel数据

如题所述

在excel处理大量数据匹配过程中,虽然可以使用vlookup,但是数据量超过10万进行批量匹配的时候,效率非常差,因此使用python。经查,发现python通过pandas库的merge可以实现类似于SQL中join的功能
import pandas as pd
import numpy as np

# %%
with pd.ExcelFile('xx.xlsx') as xls:
df1 = pd.read_excel(xls,'Sheet1')
df2 = pd.read_excel(xls,'Sheet2')

outer=pd.merge(df1,df2,on='key')

outer.to_excel('outer_function.xlsx',index=False,encoding='utf-8')
最终实现Sheet1和Sheet2基于相同key字段的匹配,拼接。
温馨提示:答案为网友推荐,仅供参考