python-3.x - Python3 Pandas.DataFrame.info() 错误键 : 30

标签 python-3.x pandas windows artificial-intelligence sklearn-pandas

所以我正在挖掘一些数据集,然后尝试使用 pandas 进行分析,然后我偶然发现了以下错误......我的大脑卡住了:(

这是引发异常的片段

import pandas as pd
from sklearn.datasets import load_breast_cancer


X, y = load_breast_cancer(return_X_y=True)
data = pd.DataFrame(X)
data['class'] = y
data.head()
data.tail()
data.columns
print('length of data is', len(data))
data.shape
data.info()

这是错误的引用

C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\Scripts\python.exe C:/Users/97150/PycharmProjects/EmbeddedLinux/AI/project.py
length of data is 569
Traceback (most recent call last):
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\core\indexes\base.py", line 2889, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 97, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 30

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/97150/PycharmProjects/EmbeddedLinux/AI/project.py", line 42, in <module>
    data.info()
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\core\frame.py", line 2587, in info
    self, verbose, buf, max_cols, memory_usage, null_counts
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\io\formats\info.py", line 250, in info
    self._verbose_repr(lines, ids, dtypes, show_counts)
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\io\formats\info.py", line 335, in _verbose_repr
    dtype = dtypes[i]
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\core\series.py", line 882, in __getitem__
    return self._get_value(key)
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\core\series.py", line 991, in _get_value
    loc = self.index.get_loc(label)
  File "C:\Users\97150\PycharmProjects\EmbeddedLinux\venv\lib\site-packages\pandas\core\indexes\base.py", line 2891, in get_loc
    raise KeyError(key) from err
KeyError: 30

Process finished with exit code 1

注意:我使用的是 PyCharm 社区 2020.2,并检查了更新等,但没有任何变化

最佳答案

所以,事实证明, Pandas 的行为很奇怪。 从 data.info() 中删除 () 解决了这个问题:)

关于python-3.x - Python3 Pandas.DataFrame.info() 错误键 : 30,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63344556/

相关文章:

windows - 进程优先级是否继承?

python - 转换数据帧值

python - 自带Python语法错误: Invalid Syntax, String's Attributes Inexisting?

python - Pandas 卡住列名

python - 计算仅在 B 列和/或 C 列中观察到的单个不同值的 A 列值

mysql - 在 Windows 8.1 上覆盖路径内容 - 环境变量

python - 如何在 Python 中读取 txt 文件的特定部分?

python - Pyqt5 鼠标事件不适用于我的自定义选项卡栏

python - 如何在 plot pandas 或 matplotlib python 中停止折线图

windows - 32 位进程能否在 64 位 Windows 操作系统上访问更多内存?