Traceback (most recent call last): File "pandas\_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 975, in pandas._libs.hashtable.Float64HashTable.get_item TypeError: must be real number, not tuple During handling of the above exception, another exception occurred: 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 103, in pandas._libs.index.IndexEngine.get_loc KeyError: (0,) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 160, in <module> n.train(train_input,train_output) File "D:\PyCharm\learning\1\11.py", line 137, in train inputs = train_input[j,] File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\frame.py", line 3024, in __getitem__ indexer = self.columns.get_loc(key) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\core\indexes\numeric.py", line 395, in get_loc return super().get_loc(key, method=method, tolerance=tolerance) 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 22:08:43 浏览: 73
根据你提供的错误信息,出现了多个异常,主要是 `KeyError` 和 `TypeError`。
首先,`KeyError` 错误发生在 `inputs = train_input[j,]` 这行代码上。根据错误信息,`(0,)` 是一个无法在 `train_input` 中找到的键值。这可能是因为你尝试使用一个不存在的列索引来访问 DataFrame 或数组的元素。
其次,`TypeError` 错误发生在 `pandas._libs.hashtable.Float64HashTable.get_item` 这行代码上。根据错误信息,这是因为需要一个实数(real number),而不是一个元组(tuple)。这可能是因为你给定的数据类型与预期类型不匹配。
为了解决这些错误,你可以检查以下几个方面:
1. 确认输入的数据类型是否正确。确保传递给 `train_input` 和 `train_output` 的参数是正确的 DataFrame 或数组。
2. 检查列索引是否存在。确认在使用列索引访问 DataFrame 或数组元素时,所使用的索引值是存在的。
3. 检查数据中是否包含非法值。确保数据中不包含非实数值(如字符串、元组等),以免引发 `TypeError` 错误。
如果问题仍然存在,请提供更多相关的代码和上下文信息,以便我能够提供更准确的帮助。
相关问题
Traceback (most recent call last): File "c:\users\lenovo\appdata\local\programs\python\python39\lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc return self._engine.get_loc(casted_key) File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'lon'
这个错误提示显示您的代码中使用了一个叫做"lon"的关键字,但是这个关键字在数据中不存在,所以导致了KeyError异常。可能的原因是您的数据中没有这个关键字,或者关键字拼写不正确。
您可以检查一下您的数据中是否真的有这个关键字,或者尝试修改关键字拼写。如果是多个关键字出现了类似的问题,可以检查一下您的数据是否完整,并且列名是否与您的代码中使用的一致。
另外,您也可以在代码中添加一些调试信息,帮助您更好地理解问题。比如可以在出现问题的代码行之前添加一行print语句,输出相关的变量值,以便您更好地理解程序的运行情况。
ERROR in app: Exception on /analyse2 [POST] Traceback (most recent call last): File "E:\python-3.7.0\lib\site-packages\pandas\core\indexes\base.py", line 2898, 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 98, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index_class_helper.pxi", line 93, in pandas._libs.index.Int64Engine._check_type KeyError: 'value' The above exception was the direct cause of the following exception:
这个错误信息看起来是在使用 Pandas 库时出现了问题。根据错误信息,可能是在调用 Pandas 的 get_loc() 方法时传入了一个不存在的键值('value'),导致了 KeyError 异常。你可以检查一下代码中是否正确传入了键值,或者查看是否有其他地方引起了这个异常。如果需要更多帮助,请提供更多的上下文信息。