I have a dataframe with a date column in the following format: 20130526T150000. How do you change this column to datetime 2013-05-26 15:00:00?

Viewed 38

Does anyone know how to change 20130526T150000 to datetime format?

1 Answers

One note: the 'T' is usefull. Use pd.to_datetime() directly, the T is actually usefull as it denotes the iso format and will help not confuse for some locales (some countries have the month first, then the day, others the oposite - iso goes from most significant to less: year, month, day)...

pd.to_datetime("20130526T150000")

Timestamp('2013-05-26 15:00:00')

If you want to be more explicit, specify the format:

pd.to_datetime("20130526T150000", format=...)

However, this might be a duplicate: How to define format when using pandas to_datetime? ... For best results, if you are doing a conversion of a column, use Convert Pandas Column to DateTime

Related