0

So I'm new to python and pandas. I'm using to_datetime function to convert 1605121950805 into a real date format. If I use:

dates=pd.to_datetime(1605121950805, infer_datetime_format=True,yearfirst=True)

I get: 1970-01-01 00:26:45.121950805

If I use format parameter it works fine:

dates=pd.to_datetime(1605121950805, format='%y%m%d%H%M%S%f')

Output: 2016-05-12 19:50:08.050000

So if I specifying a format it works but I would like to know is there any way to make it work without format parameter, so infer_datetime_format can guess the right format?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
  • Have you tried converting 1605121950805 (which is an integer) to string? – Błotosmętek Jun 04 '17 at 16:23
  • 1
    Whats wrong with passing a format? The `1605121950805` can be ambiguously parsed into many different dates. How is `to_datetime` supposed to choose which one you meant? You need to give it some help. Now if you used something less ambiguous, it can infer. But infer isn't a synonym for mind read. – piRSquared Jun 04 '17 at 16:51
  • @Błotosmętek yes I did and I get an error with this: OverflowError: Python int too large to convert to C long. – Miljenko Dujić Jun 05 '17 at 07:02
  • @piRSquared There is nothing wrong, but I'm trying to make like a smart parser which can extract that date from file, and if I give him format I'm not sure is that smart enough. I thought that maybe I was doing something wrong.That is why I try to find other way around, if not I will use it with format. Any suggestion for other method? – Miljenko Dujić Jun 05 '17 at 07:02

0 Answers0