I have a Dataframe with stock prices. Example below but this goes on for 4500 lines of stock prices
>>
DATE MMM US Equity AIR US Equity
1/3/2000 47.19 17.56
1/4/2000 45.31 17.63
1/5/2000 46.63 17.81
1/6/2000 50.38 17.94
I have created moving average using iteritems with the follow
>>>for stockname, stock in df.iteritems():
# Create 10,30,50,100 and 200D MAvgs
MA10D = stock.rolling(10).mean()
MA30D = stock.rolling(30).mean()
MA50D = stock.rolling(50).mean()
MA100D = stock.rolling(100).mean()
MA200D = stock.rolling(200).mean()
df_stockname = pd.concat([df[[1]],MA10D,MA30D,MA50D,MA100D,MA200D],axis=1)
The problem is this only shows the last item in the loop (the AIR US Equity stock). How do I access MA10D, MA30D, etc for the first stock in the loop (ie the MMM US Equity which is the first stock in the df). How can I do this
I ultimately want to be able to create two data frames, one for each stock with the stock price, MA10D, MA30D, MA50D, MA100D and MA200D. So I ultimate need a way to name each dataframe and change the df[[#]] within the concat.
Is this what you are trying to do?
Here is a complete version that should execute and the results:
Output: