0

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

Bon Brown
  • 17
  • 2

1 Answers1

-1

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

ntg
  • 12,950
  • 7
  • 74
  • 95
  • When i try that it comes up with a parsing error - ParserError: month must be in 1..12: 20121711T150000 – Bon Brown Sep 12 '22 at 11:29
  • I have noticed, this actually should not be happening... https://stackoverflow.com/questions/73688212/pandas-to-datetime-format-bug btw, what pandas version do you use? – ntg Sep 12 '22 at 11:32
  • (use e.g. `print (pd.__version__)` ... Also, python version?) – ntg Sep 12 '22 at 11:38