-1

Hi I have this piece of code. I want to add date and specific time in hours and seconds together. But it results in this error: TypeError: dtype datetime64[ns] cannot be converted to timedelta64[ns]

These are my data:

#converting dates in 'string' to 'date' data type
#It is written in this format: 18.04.2017
df['Start Date']=df['Start Date'].astype('datetime64[ns]')

#converting times in 'string' to 'date' data type
#It is written in this format: 17:30
df['Start Time']=df['Start Time'].astype('datetime64[ns]')

What I am trying to do:

df['Start'] = df['Start Date'] + df['Start Time']

this results in this error: TypeError: dtype datetime64[ns] cannot be converted to timedelta64[ns]

#my expected result is this:

18.04.2017 17:30

1 Answers1

0

Use:

df['Start'] = pd.to_datetime(df['Start Date'] + ' ' + df['Start Time'])
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252