I have the following code written for me. The problem is it works in a separate, new document, but when I try to apply it to my dataframe which has datetime as index it doesn't work. Gives errors. Any idea how to modify it so it can on a datetime.index df? Thank you in advance!
The error I get, pointing at the last line of the code below, is:
TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting n
, use `n *
import pandas as pd
import numpy as np
Z30 = [1,1.2,0.85,0.50,-0.50,-1.20,-1.85,0.75,1.5,2]
df = pd.DataFrame(Z30)
df.columns = ['Z30']
df['Z30DELTA'] = 0
def condition(df,i):
if df.loc[i, 'Z30'] > 1 or df.loc[i, 'Z30'] < -1:
return 1
else:
return 0
for i in range(1, len(df)):
df.loc[i, 'Z30DELTA'] = df.loc[i-1, 'Z30DELTA'] + df.loc[i, 'Z30']* condition(df,i)