Traceback (most recent call last): File "C:\Users\罗康康\PycharmProjects\pythonProject\shiyan 8 - 1.py", line 6, in <module> df = pd.read_csv(r'C:\Users\罗康康\PycharmProjects\pythonProject\data.csv') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\罗康康\PycharmProjects\pythonProject\venv\Lib\site-packages\pandas\io\parsers\readers.py", line 912, in read_csv return _read(filepath_or_buffer, kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\罗康康\PycharmProjects\pythonProject\venv\Lib\site-packages\pandas\io\parsers\readers.py", line 577, in _read parser = TextFileReader(filepath_or_buffer, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\罗康康\PycharmProjects\pythonProject\venv\Lib\site-packages\pandas\io\parsers\readers.py", line 1407, in __init__ self._engine = self._make_engine(f, self.engine) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\罗康康\PycharmProjects\pythonProject\venv\Lib\site-packages\pandas\io\parsers\readers.py", line 1679, in _make_engine return mapping[engine](f, **self.options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\罗康康\PycharmProjects\pythonProject\venv\Lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 93, in __init__ self._reader = parsers.TextReader(src, **kwds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pandas\_libs\parsers.pyx", line 548, in pandas._libs.parsers.TextReader.__cinit__ File "pandas\_libs\parsers.pyx", line 637, in pandas._libs.parsers.TextReader._get_header File "pandas\_libs\parsers.pyx", line 848, in pandas._libs.parsers.TextReader._tokenize_rows File "pandas\_libs\parsers.pyx", line 859, in pandas._libs.parsers.TextReader._check_tokenize_status File "pandas\_libs\parsers.pyx", line 2017, in pandas._libs.parsers.raise_parser_error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte是什么意思
时间: 2023-07-20 09:43:58 浏览: 97
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误提示表明在读取CSV文件时出现了Unicode解码错误,Python无法将文件内容以UTF-8编码解码。这通常是因为文件实际上不是以UTF-8编码保存的,而是使用了其他编码格式。解决这个问题的方法是在读取文件时指定正确的编码格式,例如:
```python
df = pd.read_csv(r'C:\Users\罗康康\PycharmProjects\pythonProject\data.csv', encoding='gbk')
```
这里假设文件实际上是以GBK编码保存的,因此在读取时指定了`encoding='gbk'`参数。你可以尝试使用其他编码格式进行读取,直到找到正确的编码格式为止。
阅读全文