Skip to content

Commit 3e56700

Browse files
committed
Convert output type in Excel for PeriodIndex in Index or MultiIndex be timestamps
1 parent dbeeb1f commit 3e56700

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/io/formats/excel.py

+7
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,9 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]:
826826
fill_value=levels._na_value,
827827
)
828828

829+
if isinstance(values, PeriodIndex):
830+
values = values.to_timestamp()
831+
829832
for i, span_val in spans.items():
830833
mergestart, mergeend = None, None
831834
if span_val > 1:
@@ -849,6 +852,10 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]:
849852
# Format hierarchical rows with non-merged values.
850853
for indexcolvals in zip(*self.df.index):
851854
for idx, indexcolval in enumerate(indexcolvals):
855+
856+
if isinstance(indexcolval, Period):
857+
indexcolval = indexcolval.to_timestamp()
858+
852859
yield CssExcelCell(
853860
row=self.rowcounter + idx,
854861
col=gcolidx,

0 commit comments

Comments
 (0)