When I run this code, it gives me an error: ValueError: Wrong number of items passed 2, placement implies 1
Am i missing something ? I looked at questions related to mine but it doesn't help me.
import pandas as pd
import pandas_ta as ta
import numpy as np
df = pd.read_csv('data/1d/AAVEUSDT-1d-data.csv')
def stoch_rsi(df, length=14):
df['stochrsi'] = ta.stochrsi(close = df['close'])
return df['stochrsi']
stoch = stoch_rsi(df)
print(stoch)
here you can find the error message :
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/si te-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 101, 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: 'stochrsi'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/si te-packages/pandas/core/generic.py", line 3576, in _set_item
loc = self._info_axis.get_loc(key)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 2900, in get_loc
raise KeyError(key) from err
KeyError: 'stochrsi'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/louis/Desktop/Python_projects/streamlit_apps/dashboards/test.py", line 20, in <module>
stoch = stoch_rsi(df)
File "/Users/louis/Desktop/Python_projects/streamlit_apps/dashboards/test.py", line 14, in stoch_rsi
df['stochrsi'] = ta.stochrsi(close = df['close'])
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/frame.py", line 3044, in __setitem__
self._set_item(key, value)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/frame.py", line 3121, in _set_item
NDFrame._set_item(self, key, value)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/generic.py", line 3579, in _set_item
self._mgr.insert(len(self._info_axis), key, value)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/internals/managers.py", line 1198, in insert
block = make_block(values=value, ndim=self.ndim, placement=slice(loc, loc + 1))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/internals/blocks.py", line 2744, in make_block
return klass(values, ndim=ndim, placement=placement)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/internals/blocks.py", line 130, in __init__
raise ValueError(
ValueError: Wrong number of items passed 2, placement implies 1