Skip to content
Advertisement

Error converting string to date field in Pandas

enter image description here

As you can infer from the above , When I try to convert the string , it gives error.

Tried below codes but got same error as,day is not defined,

df['day'] = pd.to_datetime(df['day'],format='%d %b %Y %H:%M:%S:%f')

As SO memeber suggested,I edited code but index stills the string, did not convert to day

enter image description here

Advertisement

Answer

If you don’t want to create another column, then just this will do:

df.index = pd.to_datetime(df.index)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement