Edamame
Edamame

Reputation: 25366

pandas: create a date time column from an existing date time column

I am trying to create a new datetime column from an existing date time column in a pandas data frame. Here is my code:

import datetime
pd.to_datetime(df['start_date'])
df['end_date'] = df['start_date'] + datetime.timedelta(days=10)

But I got the following errors:

TypeError: coercing to Unicode: need string or buffer, datetime.timedelta found

What did I do wrong here and how do I fix this? Thanks!

Upvotes: 0

Views: 66

Answers (1)

BENY
BENY

Reputation: 323226

Do something with Timedelta like

df['end_date'] = pd.to_datetime(df.start_date) + pd.Timedelta(10 , unit = 'D')

Upvotes: 2

Related Questions