-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_excel inserts invalid data if a level in a MultiIndex is None #51252
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
Comments
I guess this is related to forward filling for round tripping purposes (see read_excel index_col documentation). But investigations welcome |
I think pandas/pandas/io/formats/excel.py Lines 641 to 660 in 13db83a
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.
|
pandas/pandas/core/indexes/base.py Line 1052 in b9a4335
This variable is set to Now it's left to figure out why it's set to 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
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
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
INSTALLED VERSIONS
commit : 2e218d1
python : 3.10.0.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_Australia.1252
pandas : 1.5.3
numpy : 1.22.4
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 57.4.0
pip : 23.0
Cython : 0.29.32
pytest : 7.2.0
hypothesis : None
sphinx : 4.5.0
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.1.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.1.0
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : 1.3.0
zstandard : 0.17.0
tzdata : None
The text was updated successfully, but these errors were encountered: