How to Read Dates from a CSV File with pandas parse_dates
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
<table> = pd.read_csv("<file>.csv", parse_dates=["<column>"])
| Part | What 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:
day,units
2026-01-05,12
2026-01-06,9
Then the script, in the same folder:
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.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/pandas-parse-dates-01-code.webp)
Step 2: Run It
uv run python read_dates.py
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.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/pandas-parse-dates-02-output.webp)
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:
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
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out parse_dates | The column's type is str, and .dt raises AttributeError: Can only use .dt accessor with datetimelike values | Pass parse_dates=["day"] |
| A file with one value that isn't a date | With a row reading not a date, the whole day column stayed str, without an error | Check the column's type after reading, and clean the bad rows |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
The column's type is str even with parse_dates | At least one value couldn't be read as a date | Find 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/2026 | The file uses day/month/year | Pass 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
- read_csv —
parse_dates,date_formatand the other options. - Time series / date functionality — working with date columns.
