运行的代码,在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])

这样就出来内容了,成功了

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐