Python问题:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb0 in position 0: invalid start byte
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 0: invalid start byte解决办法
·
运行的代码,在jupyter notebook中运行的
df = pd.read_csv('weather_new.csv',encoding='utf-8',header=[0,1],index_col=[0,1])
df
报错:
D:\python\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds) 2008 kwds["usecols"] = self.usecols 2009 -> 2010 self._reader = parsers.TextReader(src, **kwds) 2011 self.unnamed_cols = self._reader.unnamed_cols 2012 pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.__cinit__() pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._get_header() pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows() pandas\_libs\parsers.pyx in pandas._libs.parsers.raise_parser_error() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 2: invalid start byte
解决方法:
首先修改encoding的值,出来发现是乱码,但是格式对
其次,将原来的语句注释掉,运行下述语句
df=pd.read_csv('weather_new.csv',encoding="gbk",header=[0,1],index_col=[0,1])
这样就出来内容了,成功了
更多推荐
已为社区贡献6条内容
所有评论(0)