sh1ng
sh1ng

Reputation: 2973

python pandas parse datetime string with months names

Can someone point me to a format or a code snippet to parse date in format like

04SEP12:00:00:00

That %dd%mm%YY:%HH:%MM:%SS doesn't work.

Upvotes: 11

Views: 16372

Answers (3)

kevin
kevin

Reputation: 1157

As another example,

pd.to_datetime("May 15, 2016", format="%b %d, %Y")
>>>Timestamp('2016-05-15 00:00:00')

Use %b for the month names.

Upvotes: 1

kevin
kevin

Reputation: 1157

Another way is simply do:

pd.to_datetime("May 15, 2016", infer_datetime_format=True)

>>>Timestamp('2016-05-15 00:00:00')

Upvotes: 8

EdChum
EdChum

Reputation: 394071

Use format string: '%d%b%y:%H:%M:%S' and pass this as the format for to_datetime, you can find the format options in the docs:

In [73]:

pd.to_datetime('04SEP12:00:00:00', format='%d%b%y:%H:%M:%S')
Out[73]:
Timestamp('2012-09-04 00:00:00')

Upvotes: 16

Related Questions