I was thinking this would be very easy but the below is not working for what I want. Just trying to compute a new date column by adding days to a pre-existing datetime column using values from another column. My 'offset' column below just has 1 digit numbers.
df['new_date'] = df['orig_date'].apply(lambda x: x + pd.DateOffset(days=df['offset']))
Error: unsupported type for timedelta days component: Series
thank you,
A bit late, but it may be useful for others with the same doubt. There is a way of doing this in a vectorised way, so it is much faster.
df['new_date'] = df['orig_date'] + df['offset'].astype('timedelta64[D]'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With