I have a time series for 10 years with daily prices for a stock index. I am looking to create multiple new columns in the dataframe "Target Date" that gives me the date 3,6,9 months forward from the original date in the date column.
Current df : Has columns 1.Date 2.Price so this line
prices['Target Date 1'] = pd.DatetimeIndex(prices['DATE']) + pd.DateOffset(months = 3)
gives me my new column
I however want to do this 20x (so 5 years out) so my df will have Target Date 1 all the way Target Date 20, and the date will be 3months forward in between each one. (so Target Date 2 column will be Date + 6 months, Target Date 3 will be date + 9 months and so on
Cant figure out how to do this in the most efficient way.
question from:
https://stackoverflow.com/questions/65843363/creating-new-forward-date-df-columns-all-at-once 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…