Code Sample, a copy-pastable example if possible

import pandas
pandas.DataFrame({(1, 2): 3, (1, 3): 1, (2, 1): 2, (2, 2): 0}, index=[0]).to_excel('test.xlsx')

Problem description

Expected behavior, observed with pandas v0.20.3

Pandas Regression in exporting of multiindex column dataframes

Behavior observed with pandas v0.21.0:

Pandas Regression in exporting of multiindex column dataframes

Note: I did not verify whether the issue is resolved on master

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.3.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-98-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_DK.UTF-8 LANG: en_US.UTF-8 LOCALE: en_DK.UTF-8 pandas: 0.21.0 pytest: 3.2.3 pip: 9.0.1 setuptools: 36.6.0 Cython: 0.27.2 numpy: 1.12.1 scipy: 0.19.1 pyarrow: None xarray: None IPython: 6.2.1 sphinx: None patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.3 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.1.0 openpyxl: 2.5.0b1 xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: 3.7.3 bs4: 4.6.0 html5lib: 0.999999999 sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.6 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

For a reference, the working configuration:

INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-98-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_DK.UTF-8 LANG: en_US.UTF-8 LOCALE: en_DK.UTF-8 pandas: 0.20.3 pytest: None pip: 9.0.1 setuptools: 36.2.2.post20170724 Cython: None numpy: 1.12.1 scipy: 0.19.1 xarray: None IPython: 6.1.0 sphinx: None patsy: 0.4.1 dateutil: 2.6.1 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.0.2 openpyxl: 2.5.0a2 xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: 0.9999999 sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.5 s3fs: None pandas_gbq: None pandas_datareader: None

Comment From: TomAugspurger

Could you try on master? This seems to be correct for me on master, but I don't think we've had any changes to the excel writer recently.

Also, could you ensure all the other libraries are on the same version? It looks like your openpyxl versions are different across the two envs.

Comment From: akhmerov

Yep, you're right, the problem is within openpyxl, and is a regression from 2.5.0a1 to 2.5.0b2.

Comment From: TomAugspurger

Thanks. Can you report that to them (and link back to it here, so when the next person comes along we can point them to it).

Comment From: akhmerov

Done: openpyxl issue.

Comment From: akhmerov

@TomAugspurger see the discussion in the issue above. openpyxl devs suggest that pandas uses internal API for cell merging.