Traceback (most recent call last): File…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Traceback (most recent call last): File "C:\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3802, in get_loc return self._engine.get_loc(casted_key) File "pandas_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 125
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Python\Sergey\BO\json\TA1.py", line 157, in if name == "main": main() File "C:\Python\Sergey\BO\json\TA1.py", line 152, in main Analiz() File "C:\Python\Sergey\BO\json\TA1.py", line 70, in Analiz if df['rsi'][i] < lower_bound: File "C:\Python\Python310\lib\site-packages\pandas\core\series.py", line 981, in getitem return self._get_value(key) File "C:\Python\Python310\lib\site-packages\pandas\core\series.py", line 1089, in _get_value loc = self.index.get_loc(label) File "C:\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3804, in get_loc raise KeyError(key) from err KeyError: 125 мои данные идут вот в таком вот виде Open Close High Low rsi time
2024-06-24 12:57:00 180.011 180.082 180.093 180.011 NaN 2024-06-24 12:58:00 180.090 180.072 180.100 180.046 NaN 2024-06-24 12:59:00 180.072 179.995 180.123 179.995 NaN 2024-06-24 13:00:00 179.991 180.047 180.090 179.953 NaN 2024-06-24 13:01:00 180.054 180.159 180.159 180.054 NaN загружаются вот таким вот способом df = pd.read_csv(file_path, index_col="time", parse_dates=["time"]) Assistant
The error you're encountering,
KeyError: 125, indicates that your code is trying to access a row in the DataFrame using an index label of125, which does not exist in your DataFrame. This is likely happening in the lineif df['rsi'][i] < lower_bound:, whereiis the index label that is causing the error.Here are a few steps to troubleshoot and resolve this issue:
-
Check the Index Type: Ensure that the index of your DataFrame is what you expect it to be. Since you are using
index_col="time"when reading the CSV, your DataFrame index should be a DateTime index. However, the error suggests that the index being used is an integer.
-