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 。
代码语言:javascript复制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:softdevelopSoftAnaconda3envstest36libsite-packagespandasioparsers.py", line 686, in read_csv return _read(filepath_or_buffer, kwds) File "D:softdevelopSoftAnaconda3envstest36libsite-packagespandasioparsers.py", line 452, in _read parser = TextFileReader(fp_or_buf, **kwds) File "D:softdevelopSoftAnaconda3envstest36libsite-packagespandasioparsers.py", line 936, in __init__ self._make_engine(self.engine) File "D:softdevelopSoftAnaconda3envstest36libsite-packagespandasioparsers.py", line 1168, in _make_engine self._engine = CParserWrapper(self.f, **self.options) File "D:softdevelopSoftAnaconda3envstest36libsite-packagespandasioparsers.py", line 1998, in __init__ self._reader = parsers.TextReader(src, **kwds) File "pandas_libsparsers.pyx", line 516, in pandas._libs.parsers.TextReader.__cinit__ File "pandas_libsparsers.pyx", line 690, in pandas._libs.parsers.TextReader._get_header File "pandas_libsparsers.pyx", line 884, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas_libsparsers.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