I have a separate column with HH:MM: SS object type. I want to convert object type to DateTime format. Encountering the error below.
Asked
Active
Viewed 306 times
0

vishal sankar
- 33
- 1
- 8
-
Could you add the code that caused this error? Just to have a clue for what you have tried already. First suspect your matching pattern is different than your field as it expects hours,mins,seconds to be separated by colons while it's actually separated by dots and/or dashes – kareem_emad Apr 22 '20 at 04:57
-
df['ACCIDENT_TIME1']=pd.to_datetime(df["ACCIDENT_TIME"],format='%H:%M:%S') @kareem_emad – vishal sankar Apr 22 '20 at 08:32
-
you should do it like this ```pd.to_datetime(df["ACCIDENT_TIME"], format="%H.%M.%S")``` – kareem_emad Apr 22 '20 at 10:40
2 Answers
1
You can try the below one also:
import pandas as pd
df['col_name'] = pd.to_datetime(df['col_name'], errors='coerce')

j suman
- 127
- 4
-
Converting the time to date format. Time format: 02.20.00 Converted: 2000-02-20 – vishal sankar Apr 22 '20 at 12:42
0
if you want to change dtype of column you can do in below way:
df['col_name'] = df['col_name'].astype('datetime64[ns]')

j suman
- 127
- 4
-
Error: day is out of range for month I feel that datetime function is looking for day in the time column and throws day error. – vishal sankar Apr 22 '20 at 08:34