Home > Blockchain >  Pandas converting date time in string to datetime format
Pandas converting date time in string to datetime format

Time:02-28

I have a column in Pandas dataframe which is a datetime entry column in string. I have tried using the the syntax but it gives rise to this error.

Syntax

pd.to_datetime(df['Datetime'], format = '%y-%m-%d %H:%M:%S')
Error
time data '2020-11-01 16:23:12' does not match format '%y-%m-%d %H:%M:%S'

CodePudding user response:

Try %Y,

this is the cheatsheet: https://strftime.org/

CodePudding user response:

Yes, you've used the wrong format for the year.

pd.to_datetime(df["Datetime"], format="%Y-%m-%d %H:%M:%S")
  • Related