pandas的read_csv读入csv文件报错'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')

 

'''
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# 不发出警告

import os
os.chdir('C:\\Users\\ou\\Desktop\\P201807226-project10\\')

#读取数据
df01=pd.read_csv('house_rent.csv',encoding='gb18030')
df02=pd.read_csv('house_sell.csv',encoding='gb18030')

 

你可能感兴趣的:(python,数据分析,mysql,bokeh,Python数据分析与实战)