Reputation: 33
I have an issue where it says:
time data '2021-08-17 05:42:48 ' does not match format '%y/%m/%d %H:%M:%S' (match)
but my code is:
df['Event_Start_Time'] = pd.to_datetime(df['Event_Start_Time'], format='%y/%m/%d %H:%M:%S')
I am not sure why the two formats are not matching
Upvotes: 1
Views: 97
Reputation: 12496
As already pointed out by Hampus Larsson in the comment, there are two typos in your code:
%Y
, not %y
-
, not /
In general, you can refer to this document for the available date and time format codes.
That being said, you should use:
df['Event_Start_Time'] = pd.to_datetime(df['Event_Start_Time'], format='%Y-%m-%d %H:%M:%S')
Upvotes: 1
Reputation: 2670
Looks like you're following my code example from the other question where I showed an example of reading in a string like 4/12/19 06:00
. Setting the format with /
in that case would work but you have to look at what you actually have.
Run df.info()
and see if the column is actually datetime already. If not look at the format you have and match it. Probably format='%Y-%m-%d %H:%M:%S'
in your case.
Upvotes: 0