Skip to content

BUG: to_csv extra header line with multiindex columns #6618

Closed
@dsm054

Description

@dsm054

This seems strange to me, but I don't often use a MultiIndex so I might be missing something obvious.

>>> pd.__version__
'0.13.1-420-g6899ed6'
>>> df2 = pd.DataFrame([1], columns=pd.MultiIndex.from_arrays([[1],[2]]))
>>> df2
   1
   2
0  1

[1 rows x 1 columns]
>>> df2.columns
MultiIndex(levels=[[1], [2]],
           labels=[[0], [0]])
>>> print df2.to_csv()
,1
,2
,
0,1

Is there supposed to be that empty line at the end of the header? Compare

>>> print df2.to_csv(header=False)
0,1

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO CSVread_csv, to_csvOutput-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