BUG: Importing Pandas-generated excel loses multiindex multicolumn names #51235
Labels
Bug
IO Excel
read_excel, to_excel
Needs Triage
Issue that has not been reviewed by a pandas team member
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
Issue Description
Exporting a multiindex pandas dataframe leaves a blank row due to indexing. The option should exist to allow for no blank row.

This problem can be "solved" by resetting the index and then exporting. This generates an empty row which is mentioned in issue #27772.

Through workarounds this row can be deleted (though this should probably be fixed, or at least given an option to choose.
Reimporting the index-reset excel yields a df which is "corrupt" in that it is not the original df generated.
Issue 1: The "index" column is included in the export. Index=False is not implemented for MultiIndex.

Issue 2: Defining the first columns as indexes drops all but the last name. (see last row of code above)
Expected Behavior
Expected behavior 1:

Exporting multiIndex dataframes should have the option to not leave a blank row due to multiIndexes.
Expected behavior 2:
Resetting the index of a multiIndex dataframe and then exporting should not generate an empty row.
Expected behavior 3:
Resetting the index of a multiIndex dataframe and then exporting should have the functionality to ignore index as mentioned in argument "index=False"
Expected behavior 4:
The column names should not be deleted/lost when reimporting the excel export.
General expectation:
Exporting and importing a df should be a "commutable" action - Generating a df, exporting it, importing, should end up with an identical df.
Installed Versions
Replace this line with the output of pd.show_versions()
pandas : 1.5.2
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
setuptools : 62.0.0
pip : 21.2.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.7
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.29.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2021.11.0
gcsfs : None
matplotlib : 3.2.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : 2021.11.0
scipy : 1.7.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: