pandas Parsing date columns with read_csv


Date always have a different format, they can be parsed using a specific parse_dates function.

This input.csv:

2016 06 10 20:30:00    foo
2016 07 11 19:45:30    bar
2013 10 12 4:30:00     foo

Can be parsed like this :

mydateparser = lambda x: pd.datetime.strptime(x, "%Y %m %d %H:%M:%S")
df = pd.read_csv("file.csv", sep='\t', names=['date_column', 'other_column'], parse_dates=['date_column'], date_parser=mydateparser)

parse_dates argument is the column to be parsed
date_parser is the parser function