Charlie Lefrak
Charlie Lefrak

Reputation: 182

python - exporting multi-index pandas dataframe to excel

I'm trying the following example from this (closed) GitHub issue: https://github.com/pandas-dev/pandas/issues/2701

import pandas as pd

m = pd.MultiIndex.from_tuples([(1,1),(1,2)], names=['a','b'])
df = pd.DataFrame([[1,2],[3,4]], columns=m)

df.to_excel('test.xls')

When I open test.xls, there is a blank line on row 3:

blank line in dataframe

The example image from GitHub doesn't have this blank line:enter image description here

Is this a bug? And are there workaround available for writing multiindex dataframes to Excel? I'd rather not go the CSV route, as pandas will do the merge-and-center for me.

Using pandas version 0.19.2 on Ubuntu 14.04 and Windows 10.

Upvotes: 1

Views: 2082

Answers (1)

Satyadev
Satyadev

Reputation: 643

I am able to reproduce whatever you have done. This is most likely a bug. No easy way out of this but to delete that row by reading the xlsx in again. Please add this to the closed github chain and reopen it.

Upvotes: 1

Related Questions