I have a column of timestamps that I would like to convert to datetime in my pandas dataframe. The format of the dates is %Y-%m-%d-%H-%M-%S
which pd.to_datetime
does not recognize. I have manually entered the format as below:
df['TIME'] = pd.to_datetime(df['TIME'], format = '%Y-%m-%d-%H-%M-%S')
My problem is some of the times do not have seconds so they are shorter
(format = %Y-%m-%d-%H-%M
).
How can I get all of these strings to datetimes?
I was thinking I could add zero seconds (-0
) to the end of my shorter dates but I don't know how to do that.