Closed
Description
Pandas version checks
- I have checked that the issue still exists on the latest versions of the docs on
main
here
Location of the documentation
https://pandas.pydata.org/docs/dev/reference/api/pandas.read_csv.html#pandas-read-csv
Documentation problem
Passing a date_format
argument to read_csv
is enough to trigger datetime parsing, i.e. parse_dates=True
is not needed:
import io
import pandas as pd
csv = io.StringIO("foo,bar\n2023-01-01,0\n2023-01-02,1\n2023-01-03,2")
df = pd.read_csv(csv, index_col="foo", date_format="%Y-%m-%d")
print(df.index)
Output:
DatetimeIndex(['2023-01-01', '2023-01-02', '2023-01-03'], dtype='datetime64[ns]', name='foo', freq=None)
This makes sense as a shortcut, but it would be nice to document this behavior, so that users know that it's intentional.
Suggested fix for documentation
The documentation for both the parse_dates
and date_format
kwargs to read_csv
should mention that when parse_dates
is not specified but date_format
is, dates will be parsed.