D:\anaconda\envs\mytest\python.exe D:/PyCharm/learning/1/BPmain.py (100, 35) (50, 35) (100, 1) (50, 1) Int64Index([5], dtype='int64') Traceback (most recent call last): File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexes\base.py", line 3081, 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 101, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 1625, in pandas._libs.hashtable.Int64HashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 1632, in pandas._libs.hashtable.Int64HashTable.get_item KeyError: 0 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\PyCharm\learning\1\BPmain.py", line 30, in <module> if test_output.loc[i, 0] == y_pred[i, 0]: File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 889, in __getitem__ return self._getitem_tuple(key) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1060, in _getitem_tuple return self._getitem_lowerdim(tup) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 831, in _getitem_lowerdim return getattr(section, self.name)[new_key] File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 895, in __getitem__ return self._getitem_axis(maybe_callable, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1124, in _getitem_axis return self._get_label(key, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexing.py", line 1073, in _get_label return self.obj.xs(label, axis=axis) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\generic.py", line 3739, in xs loc = index.get_loc(key) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexes\base.py", line 3083, in get_loc raise KeyError(key) from err KeyError: 0 进程已结束,退出代码1
时间: 2023-07-22 15:08:13 浏览: 173
Anaconda3-2022.10-Windows-x86-64.exe
根据您提供的错误信息,问题出现在以下代码中:
```python
if test_output.loc[i, 0] == y_pred[i, 0]:
```
出现了KeyError: 0的错误。这个错误通常表示您正在尝试访问一个不存在的索引或键。
根据您的代码,我推测问题可能出现在您尝试通过使用`test_output.loc[i, 0]`来访问test_output DataFrame中的元素时。请注意,DataFrame的loc方法需要传递列名作为参数,而不是使用索引。
修改您的代码如下:
```python
if test_output.loc[i, 'column_name'] == y_pred[i, 0]:
```
请将'column_name'替换为test_output DataFrame中包含所需值的列的实际名称。确保您使用正确的列名来访问DataFrame中的元素。
此外,还要注意,y_pred是一个二维数组,所以您需要使用y_pred[i, 0]来访问第i行的值。
如果您不确定要使用的列名,请使用`print(test_output.columns)`来查看DataFrame中所有的列名。
请确保您已正确加载数据并且test_output DataFrame中确实包含要访问的列和索引。如果问题仍然存在,请提供更多的代码和数据细节,以便我能够更好地帮助您解决问题。
阅读全文