I need to parse strings like "28-05-2014_02:44:32.630" from the Pandas lib.
The following code works like a charm with standard ISO date "28-05-2014T02:44:32.630":
In [1]: import dateutil.parser
In [3]: dateutil.parser.parse("28-05-2014T02:44:32.630", dayfirst=True)
Out[3]: datetime.datetime(2014, 5, 28, 2, 44, 32, 630000)
But not with my input string:
In [4]: dateutil.parser.parse("28-05-2014_02:44:32.630", dayfirst=True)
...
ValueError: unknown string format
How can i define my own parser ?
Thk in advance !
(edit)
Here is my working code (thanks to roippi):
import pandas
from datetime import datetime
def my_date_parser(d):
return datetime.strptime(d, '%d-%m-%Y_%H:%M:%S.%f')
i = pandas.read_csv('test.tsv', sep='\t', index_col=0, parse_dates=True, date_parser=my_date_parser)
...