UnicodeEncodeError:‘utf-8‘ codec can‘t encode characters in position 380-382: surrogates not allowed


考虑是某些字符无法解码为utf-8的编码格式,把dataframe(meta)的元素,在编码过程中,先把无法转化为utf-8格式的字符‘ignore’掉,再进行解码。

 

for i in meta:
    for j in meta.index:
        meta.loc[j,i] = meta.loc[j,i].encode('UTF-8','ignore').decode('UTF-8')

最后再将DataFrame写入csv或者excel

 

meta.to_csv('metaData_+C_0.csv')
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值