-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Open
Labels
Description
First reported in #51459
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
>>> import pandas as pd
>>> data = pd.DataFrame(pd.period_range(start="2000-01-01", periods=1, freq="H"))
>>> print(data.to_csv())
,0
0,2000-01-01 00:00
1,2000-01-01 01:00
>>> print(data.to_csv(date_format="%Y-%m-%d___%H:%M:%S"))
,0
0,2000-01-01 00:00
1,2000-01-01 01:00
>>> print(data.set_index(0).to_csv(date_format="%Y-%m-%d___%H:%M:%S"))
0
2000-01-01___00:00:00
2000-01-01___01:00:00Issue Description
to_csv does not take into account date_format for PeriodArrays that are normal columns the dataframe. Only PeriodIndex are correctly formatted.
Expected Behavior
The formatting should be right even if the period array is not the index