0

I am trying to create a new datetime column from existing columns (one datetime column and another integer column) in a pandas data frame. Here is my code:

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

But I got the following errors:

ValueError: Value must be Timedelta, string, integer, float, timedelta or convertible

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

2
  • pd.to_datetime(df['start_date']) + pd.Timedelta(df.total_waiting_days, unit='D').............. Commented Apr 6, 2018 at 19:35
  • @Wen : still same error by doing above Commented Apr 6, 2018 at 19:43

1 Answer 1

1

Seems like you want to convert whole column to Timedelta

df['end_date'] = df['start_date'] + df.total_waiting_days.apply(lambda x :pd.Timedelta(x, unit='D'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.