1. 程式人生 > >繁體和簡體轉化

繁體和簡體轉化

from langconv import *

def simple2tradition(line):
#將簡體轉換成繁體
line = Converter('zh-hant').convert(line)
return line

def tradition2simple(line):
# 將繁體轉換成簡體
line = Converter('zh-hans').convert(line)
return line
if __name__=="__main__":
traditional_sentence = '憂鬱的臺灣烏龜'
simplified_sentence = tradition2simple(traditional_sentence)
print(simplified_sentence)

simplified_sentence = '憂鬱的臺灣烏龜'
traditional_sentence = simple2tradition(simplified_sentence)
print(traditional_sentence)


 data=pd.DataFrame({
'name': ['a', 'b'],
'comment':['憂鬱的臺灣烏龜','憂鬱的臺灣烏龜']

})
print(data)
mychage=lambda x:tradition2simple(x)
data.loc[:,'comment']=data.loc[:,'comment'].apply(mychage)
print(data)