Skip to content

BUG: Convert output type in Excel for MultiIndex with period levels #60182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 22, 2024
Merged
7 changes: 7 additions & 0 deletions pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]:
fill_value=levels._na_value,
)

if isinstance(values, PeriodIndex):
values = values.to_timestamp()

for i, span_val in spans.items():
mergestart, mergeend = None, None
if span_val > 1:
Expand All @@ -849,6 +852,10 @@ def _format_hierarchical_rows(self) -> Iterable[ExcelCell]:
# Format hierarchical rows with non-merged values.
for indexcolvals in zip(*self.df.index):
for idx, indexcolval in enumerate(indexcolvals):

if isinstance(indexcolval, Period):
indexcolval = indexcolval.to_timestamp()

yield CssExcelCell(
row=self.rowcounter + idx,
col=gcolidx,
Expand Down
Loading