当前位置:   article > 正文

Pandas的read_csv读入csv文件报错'utf-8' codec can't decode byte 0xe5 in position 0: invalid start byte_pd.read_csv 'utf-8' codec can't decode byte

pd.read_csv 'utf-8' codec can't decode byte

Pandas读取CSV文件时,设置'utf-8','gb2312' 两种编码都报错,最终改为 'gb18030'读取成功。

  1. import pandas as pd
  2. filepath = 'C:/Users/Desktop/datas.csv'
  3. datas = pd.read_csv('filepath',encoding='utf-8')

报错:'utf-8' codec can't decode byte 0xe5 in position 0: invalid start byte

datas = pd.read_csv(filepath, encoding ='gb2312')

报错:'gb2312' codec can't decode byte 0xad in position 8: illegal multibyte sequence

正确编码格式为:

datas = pd.read_csv(filepath,encoding='gb18030')

原因是文件中可能包含有中文字符、特殊字符等内容。
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/539578
推荐阅读
相关标签
  

闽ICP备14008679号