Open musshorn opened 1 year ago
I guess this is related to forward filling for round tripping purposes (see read_excel index_col documentation). But investigations welcome
I think https://github.com/pandas-dev/pandas/blob/13db83ad3f1245107151e6a626537a8ea7f72df1/pandas/io/formats/excel.py#L641-L660 is the offending loop. When it reaches the last level, levels.take(level_codes)
gets passed [0, 1, 0, 1, -1]
which sets values
to ['Class A', 'Class B', 'Class A', 'Class B', 'Class B']
and that's ultimately the row that gets written to Excel.
This variable is set to False
for your case. When I manually set it to True
in my debugger I get the expected Excel output.
Now it's left to figure out why it's set to False
automatically...
Can I take it?
Yeah all yours, I was just trying to provide some starting research for whoever took it up
take
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When a level in a
MultiIndex
isNone
, the resulting dataframe when exported to excel has an invalid level inserted replacing theNone
. See Image.Expected Behavior
I would expect the result from
to_excel
should reflect the levels in theMultiIndex
correctly.Installed Versions