Different datetime formats pandas can auto detect

Viewed 418
In [29]: import pandas as pd
In [30]: pd.to_datetime(pd.Series(["02-04-1995","02/04/1996", "12/31/1996"]))
Out[30]:
0   1995-02-04
1   1996-02-04
2   1996-12-31
dtype: datetime64[ns]

I have given 2 different datetime formats. Pandas can autodetect the format. In the value 12/31/1996 I have given in the format mm/dd/yyyy. It can still detect the correct format without explicitly giving it.

So, Which all formats or values can pandas to_datetime() can auto-detect?

1 Answers

I would start looking into dateutil module (for example here), how this module parses string for datetime:

JUMP = [" ", ".", ",", ";", "-", "/", "'",
        "at", "on", "and", "ad", "m", "t", "of",
        "st", "nd", "rd", "th"]

According to this, you can do:

print( pd.to_datetime(pd.Series(["02and04and1995","02'04'1996", "12;31;1996"])) )

Prints:

0   1995-02-04
1   1996-02-04
2   1996-12-31
dtype: datetime64[ns]
Related