赞
踩
Pandas读取CSV文件时,设置'utf-8','gb2312' 两种编码都报错,最终改为 'gb18030'读取成功。
- import pandas as pd
-
- filepath = 'C:/Users/Desktop/datas.csv'
-
- 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')
原因是文件中可能包含有中文字符、特殊字符等内容。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。