Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

pandas - Creating new forward date df columns all at once

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...