Parsing a Date Column When Reading a CSV with Pandas


To parse columns as a datetime data type when reading a csv into a Pandas dataframe, simply pass a list of column names that contain dates into the parse_dates parameter.

In the example below we parse the columns order_date and shipping_date as datetime data types.

 1|  import pandas as pd
 3|  date_columns = ['order_date', 'shipping_date']
 4|  df = pd.read_csv('sales.csv', parse_dates=date_columns
Did you find this snippet useful?

Sign up for free to to add this to your code library