Hi,
How to create a diff. between the current value and the value of 2 periods before in the below code:
df['RSI_14'] = talib.RSI(df['Close'], timeperiod=14)
I want to add a column in the df that shows how much RSI has changed in Last three periods. and the drop RSI column
Thanks
Hello Ashish,
You can get the difference between the value at the current bar and 2 bars prior using the diff function. You can also save it in a new column as shown below.
df['RSI_change'] = df['RSI_14'].diff(period=2)
The old column can be deleted like this:
df.drop(['RSI_14'],axis=1,inplace=True)
For reference:
pandas.DataFrame.diff — pandas 2.2.3 documentation
pandas.DataFrame.drop — pandas 2.2.3 documentation
I am getting the folloing error when using the above function:
diff() got an unexpected keyword argument 'period'
Hello Ashish,
You can directly pass the number like this:
df['RSI_14'].diff(2)