Skip to content

BUG: DataFrame.to_excel(index=False) misplaces data/columns in MultiIndex case #5616

Closed
@aldanor

Description

@aldanor

Example:

>>> df = pd.DataFrame({'a': [10, 20], 'b': [30, 40], 'c': [50, 60]}, 
...                   index=pd.MultiIndex.from_tuples([(70, 80), (90, 100)]))
>>> writer = pd.ExcelWriter('test.xls')
>>> df.to_excel(writer, sheet_name='1', index=False)
>>> writer.save()
>>> pd.read_excel('test.xls', '1')
        a   b   c
10 30  50 NaN NaN
20 40  60 NaN NaN

The column names are obviously misplaced (erroneously shifted to the right by the number of levels in the MultiIndex). Or is it the data that is misplaced? Wonder why no one noticed this before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO Excelread_excel, to_excelOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions