When you are using pct_change for Close
, you didn't need to going through loop. Just simple like that:
import pandas as pd
df = pd.read_excel('StackOverFlow.xlsx', sheet_name='Sheet1')
df['Operation'] = df['Close'].pct_change()
df
Besides that, I suggest you utilize pandas dataframe by field name, it could be easier for maintenance
for index, row in df.iterrows():
close = row['Close']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…