If the regular methods dont work you can always fallback on writing your own parser. Make a function which accepts the columns from parse_dates
and returns a datetime
and add that functions with date_parser
.
So something like:
df = pd.read_csv(file, header=None, index_col='datetime',
parse_dates={'datetime': [1,2,3,4]},
date_parser=lambda x: pd.datetime.strptime(x, '%Y %m %d %H'))
Returns:
0 5
datetime
2011-01-01 21:00:00 50136 9792
2011-01-01 22:00:00 50136 9794
2011-01-01 23:00:00 50136 9796
2011-01-01 00:00:00 50136 9798
2011-01-01 01:00:00 50136 9799
2011-01-01 02:00:00 50136 9802
edit:
Perhaps its more clear if you write it like a normal function instead of a lambda:
def dt_parse(date_string):
dt = pd.datetime.strptime(date_string, '%Y %m %d %H')
return dt