Traceback (most recent call last): File "D:\project\FILE_opr.py", line 50, in <module> file=pd.read_csv("./RP_score.csv",dtype="gbk") File "D:\ProgramData\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper return func(*args, **kwargs) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper return func(*args, **kwargs) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv return _read(filepath_or_buffer, kwds) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 605, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 1442, in __init__ self._engine = self._make_engine(f, self.engine) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 1753, in _make_engine return mapping[engine](f, **self.options) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 78, in __init__ kwds["dtype"] = ensure_dtype_objs(kwds.get("dtype", None)) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 433, in ensure_dtype_objs return pandas_dtype(dtype) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\core\dtypes\common.py", line 1781, in pandas_dtype npdtype = np.dtype(dtype) TypeError: data type 'gbk' not understood
时间: 2023-06-30 07:15:39 浏览: 176
这个错误是因为 `read_csv()` 函数中的 `dtype` 参数类型不正确。在 `dtype` 参数中,应该指定列的数据类型,而不是整个文件的编码格式。你可以尝试将 `dtype` 参数设置为一个字典,其中包含每个列的数据类型。例如,如果你的文件包含两列,分别为 `col1` 和 `col2`,你可以使用以下代码:
```python
import pandas as pd
file = pd.read_csv("./RP_score.csv", dtype={"col1": str, "col2": float})
```
这里将 `col1` 设置为字符串类型,将 `col2` 设置为浮点数类型。你需要根据你的数据文件中的列名和数据类型修改这个代码。
阅读全文