From https://github.com/pandas-dev/pandas/issues/2586
Currently, once can to
read_csv(path, parse_dates=True, date_parser=lambda x: to_datetime(x, format=fmt)
and the suggestion is to add a date_format
argument such that you could do
read_csv(path, parse_dates=True, date_format=fmt)
and have it do the same thing
Comment From: luke396
take
Comment From: MarcoGorelli
wait, this needs discussion
Comment From: luke396
There is something wrong, when
data = """a,b
27.03.2003 14:55:00.000,1
03.08.2003 15:20:00.000,2"""
fmt = "%d.%m.%Y %H:%M:%S.%f"
pd.read_csv(io.StringIO(data),
index_col=0,
date_parser=lambda x: pd.to_datetime(x, fmt),
parse_dates=True,
)
That will raise an AssertionError
, but maybe because of my own problems, may be it has nothing with this issue. I just want to point it.
Comment From: MarcoGorelli
please wait, this needs discussion about whether or not this keyword needs adding
Comment From: MarcoGorelli
closing in favour of https://github.com/pandas-dev/pandas/issues/50601