Parsing a Date Column When Reading a CSV with Pandas

Import and Export

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
1 Upvote
Tags: Csv | Read_csv
Did you find this snippet useful?

Sign up to bookmark this in your snippet library