Issue
I am trying to set date format to a pandas dataframe column.
test['Date']=pd.to_datetime(test['Date'], format='%d-%m-%Y')
However, I get this error:
ValueError: time data '13/04/2021 15:21' does not match format '%d-%m
m-%Y' (match)
Why I cannot format this date column to day-month-year format?
Solution
You can either leave the format keyword out entirely, and pandas will automatically detect the format, or change it to match the format indicated. I'd suggest leaving it out, in case your column has different formats included.
But this would work for the value indicated:
test['Date'] = pd.to_datetime(test['Date'], format='%d/%m/%Y %H:%M')
Answered By - AlecZ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.