Skip to main content

How to Read Dates from a CSV File with pandas parse_dates

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A CSV file stores dates as text, and pandas reads them as text unless you tell it otherwise. Pass the date columns to parse_dates and they arrive as real dates, ready for date functions, comparisons and splits by time. This guide reads a small file with pandas 3.1.2 on Python 3.15.2.

Syntax​

Syntax
<table> = pd.read_csv("<file>.csv", parse_dates=["<column>"])
PartWhat it means
parse_dates=["<column>"]A list of the columns to read as dates
date_format="<format>"Optional. The dates' layout, such as "%d/%m/%Y" for day/month/year

The read_csv reference describes the list form: "list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column."

The Example​

sales.csv has two days of bike sales: a day column and the units sold. The script reads the file with day as a date column, prints the column types and the name of each day.

Prerequisites​

  • pandas in your project, for example with uv add pandas. This guide uses pandas 3.1.2 on Python 3.15.2.

Step 1: Create the File and the Script​

Save this as sales.csv:

sales.csv
day,units
2026-01-05,12
2026-01-06,9

Then the script, in the same folder:

read_dates.py
import pandas as pd

sales = pd.read_csv("sales.csv", parse_dates=["day"])

print(sales.dtypes)
print(sales["day"].dt.day_name())

The read_dates.py script in a macOS-style code window: import pandas, read sales.csv with parse_dates=["day"], then print the column types and the day names.

Step 2: Run It​

Terminal
uv run python read_dates.py
Output
day datetime64[us]
units int64
dtype: object
0 Monday
1 Tuesday
Name: day, dtype: str

The terminal after uv run python read_dates.py: day is datetime64[us] and units int64, then the day names Monday and Tuesday.

day became datetime64[us], pandas' date-and-time type, stored to the microsecond. Because it's a real date now, .dt.day_name() worked: 5 January 2026 was a Monday. The command works unchanged in PowerShell.

Without parse_dates​

The same file read with plain pd.read_csv("sales.csv") keeps day as text, and the date function fails:

Output
day str
units int64
dtype: object
Traceback (most recent call last):
...
AttributeError: Can only use .dt accessor with datetimelike values. Did you mean '.at' instead of '.dt'?

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out parse_datesThe column's type is str, and .dt raises AttributeError: Can only use .dt accessor with datetimelike valuesPass parse_dates=["day"]
A file with one value that isn't a dateWith a row reading not a date, the whole day column stayed str, without an errorCheck the column's type after reading, and clean the bad rows

Troubleshooting​

SymptomLikely causeFix
The column's type is str even with parse_datesAt least one value couldn't be read as a dateFind the odd value. The reference's advice for other layouts: "For non-standard datetime parsing, use to_datetime() after read_csv()"
Day and month swapped in dates such as 05/01/2026The file uses day/month/yearPass date_format="%d/%m/%Y"

FAQ​

How do I read dates written day/month/year?​

Give the layout. date_format="%d/%m/%Y" read 05/01/2026 and 06/01/2026 as 5 and 6 January 2026.

What does the [us] in datetime64[us] mean?​

Microseconds, the smallest step the column stores. pandas' time series guide says: "The default resolution for date times and time deltas is microsecond (“us”)".

Conclusion​

pd.read_csv("sales.csv", parse_dates=["day"]) read day as datetime64[us], so .dt.day_name() worked. Without it the column stayed text and .dt failed. Use date_format when dates aren't in year-month-day order.

Additional Resources​