[ACCEPTED]-Python Pandas DateOffset using value from another column-time-series
Accepted answer
In [12]: df['C'] = df['A'] + df['B'].apply(pd.offsets.Day)
In [13]: df
Out[13]:
A B C
0 2013-01-01 0 2013-01-01
1 2013-01-02 1 2013-01-03
2 2013-01-03 2 2013-01-05
3 2013-01-04 3 2013-01-07
4 2013-01-05 4 2013-01-09
0
A bit late, but it may be useful for others 2 with the same doubt. There is a way of doing 1 this in a vectorised way, so it is much faster.
df['new_date'] = df['orig_date'] + df['offset'].astype('timedelta64[D]'))
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.