df['date_col'] = pd.to_datetime(df['date_col'], format='%Y-%m-%d %H:%M:%S')
%Y - Year as decimal number (2004)
%m - month as zero padded number (03)
%d - Day of the month (16)
%H - Hour in 24 hour format
%M - Minutes (16)
%S - Seconds (03)
For more formats visit - https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior
Add other characters to match the exact format of the date
as given in your dataset (':', '-' etc)
dfc['Time_of_Sail'] = pd.to_datetime(dfc['Time_of_Sail'],format= '%H:%M:%S' ).dt.time
# convert the 'Date' column to datetime format
df['Date'] = df['Date'].astype('datetime64[ns]')
# Check the format of 'Date' column
df.info()
In [51]:
pd.to_datetime(df['I_DATE'])
Out[51]:
0 2012-03-28 14:15:00
1 2012-03-28 14:17:28
2 2012-03-28 14:50:50
Name: I_DATE, dtype: datetime64[ns]