美文网首页
python pandas-->简体繁体互转,且写入DataFr

python pandas-->简体繁体互转,且写入DataFr

作者: 默直 | 来源:发表于2020-12-11 10:18 被阅读0次

基础数据:

import pandas as pd
import numpy as np
import opencc #繁体简体互转

data=pd.read_csv('data_test.csv',encoding='gbk')
data.head()
image.png

1.安装opencc-python-reimplemented

pip install opencc-python-reimplemented

2.简体转繁体,并写到DataFrame

list_1=[]
for i in range(data.shape[0]):
    # t2s - 繁体转简体
    # s2t - 简体转繁体
    op_cc=opencc.OpenCC('s2t')
    opc=op_cc.convert(data.loc[i]['出发地 '])
    list_1.append(opc)
#将转化的繁体,写入到DataFrame
data['出发地_繁体']=list_1
data
image.png
注:参考:https://mbd.baidu.com/newspage/data/landingshare?pageType=1&isBdboxFrom=1&context=%7B%22nid%22%3A%22news_9766458758643458375%22%2C%22sourceFrom%22%3A%22bjh%22%7D

相关文章

网友评论

      本文标题:python pandas-->简体繁体互转,且写入DataFr

      本文链接:https://www.haomeiwen.com/subject/itkawktx.html