Search code examples
pythonpandasxlsxwriter

MultiIndex DataFrame to Excel export problems


After exporting MultiIndex DataFrame to an Excel file, an additional row between the header and the rows is created. How can I avoid that? enter image description here

writer = pd.ExcelWriter(out_xlsx, engine='xlsxwriter')
df1.to_excel(writer, sheet_name='All Instances', merge_cells=True)

Did anyone experience similar behaviour?


Solution

  • That is a known issue/feature in Pandas. See this GitHub Issue for an explanation.

    This Stack Overflow answer is probably the best workaround I’ve seen.