UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd6 in position 19: invalid continuation byte
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码
解決方案:
修改字符集,从 utf-8改成gbk 。
import pandas as pd
df = pd.read_csv(filepath_or_buffer='E:\\tmp\\2\\result.csv',encoding='utf-8',index_col=0,header=2)
print(df)
問題如下:
Traceback (most recent call last): File "E:/workspace/nlp_workspace/nlpdata/tmp/zhijian0824.py", line 2, in <module> df = pd.read_csv(filepath_or_buffer='E:\\tmp\\2\\result.csv',encoding='utf-8',index_col=0,header=2) File "D:\soft\developSoft\Anaconda3\envs\test36\lib\site-packages\pandas\io\parsers.py", line 686, in read_csv return _read(filepath_or_buffer, kwds) File "D:\soft\developSoft\Anaconda3\envs\test36\lib\site-packages\pandas\io\parsers.py", line 452, in _read parser = TextFileReader(fp_or_buf, **kwds) File "D:\soft\developSoft\Anaconda3\envs\test36\lib\site-packages\pandas\io\parsers.py", line 936, in __init__ self._make_engine(self.engine) File "D:\soft\developSoft\Anaconda3\envs\test36\lib\site-packages\pandas\io\parsers.py", line 1168, in _make_engine self._engine = CParserWrapper(self.f, **self.options) File "D:\soft\developSoft\Anaconda3\envs\test36\lib\site-packages\pandas\io\parsers.py", line 1998, in __init__ self._reader = parsers.TextReader(src, **kwds) File "pandas\_libs\parsers.pyx", line 516, in pandas._libs.parsers.TextReader.__cinit__ File "pandas\_libs\parsers.pyx", line 690, in pandas._libs.parsers.TextReader._get_header File "pandas\_libs\parsers.pyx", line 884, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas\_libs\parsers.pyx", line 2013, in pandas._libs.parsers.raise_parser_error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 19: invalid continuation byte