可以读取文件1文件2为数据框df1,df2,然后将df1中姓名与学号键值对写成字典,在df2中使用map函数即可(excel2016测试通过)。参考代码:
import pandas as pd
df1=pd.read_excel('a1.xlsx')
df2=pd.read_excel('a2.xlsx')
a1={x:y for x ,y in zip(df1['姓名'],df1['学号'])}
df2['学号']=df2['姓名'].map(a1)
df2.to_excel('a2.xlsx',index=False)
如有帮助,请点采纳。