当前位置:   article > 正文

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

utf-8' codec can't decode byte 0xb2 in position 0: invalid start byte

 

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

read_csv(filename, encoding ='utf-8')

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

read_csv(filename, encoding ='gb2312')

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

正确代码:read_csv(filename, encoding = 'gb18030')

 

  1. '''
  2. import numpy as np
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. import warnings
  6. warnings.filterwarnings('ignore')
  7. # 不发出警告
  8. import os
  9. os.chdir('C:\\Users\\ou\\Desktop\\P201807226-project10\\')
  10. #读取数据
  11. df01=pd.read_csv('house_rent.csv',encoding='gb18030')
  12. df02=pd.read_csv('house_sell.csv',encoding='gb18030')

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号