import osimport pandas as pdfrom xpinyin import Pinyindownpath='/Users/Kangyongqing/Downloads/'
file1='教师姓名转拼音.xlsx'dt=pd.read_excel(downpath+file1)
print(dt.info())
dt['pinyin']=dt['教师姓名'].apply(lambda x:Pinyin().get_pinyin(x).split('-')[0].capitalize()+' '+''.join(Pinyin().get_pinyin(x).split('-')[1:]).capitalize())
dt['pinyin1']=dt['教师姓名'].apply(lambda x:''.join(Pinyin().get_pinyin(x).split('-')[1:]).capitalize()+' '+Pinyin().get_pinyin(x).split('-')[0].upper())
print(dt)dt.to_excel(downpath+'教师姓名转拼音完毕.xlsx',index=False)
结果如下: