关注微信公共号:小程在线
关注CSDN博客:程志伟的博客
df1 = pd.read_csv('F:\Python\科室数据.csv',encoding='UTF-8')
df1.head(3)
Traceback (most recent call last):
File "<ipython-input-7-ea22cad5d7ab>", line 2, in <module>
encoding='UTF-8')
File "E:\anaconda3\lib\site-packages\pandas\io\parsers.py", line 676, in parser_f
return _read(filepath_or_buffer, kwds)
File "E:\anaconda3\lib\site-packages\pandas\io\parsers.py", line 448, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "E:\anaconda3\lib\site-packages\pandas\io\parsers.py", line 880, in __init__
self._make_engine(self.engine)
File "E:\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1114, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "E:\anaconda3\lib\site-packages\pandas\io\parsers.py", line 1891, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 529, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 719, in pandas._libs.parsers.TextReader._get_header
File "pandas\_libs\parsers.pyx", line 915, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 2062, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 0: invalid start byte
解决方法:
df1 = pd.read_csv('F:\Python\科室数据.csv',encoding='gbk')
df1.head(3)
Out[8]:
机构 科室 就诊人数 增长率
0 第一人民医院 内科 35188.0 9.98%
1 第一人民医院 外科 28467.0 11.27%
2 第一人民医院 妇科 13747.0 2.54%