multiindex column in to_excel #2701

Closed
hayd opened this Issue Jan 15, 2013 · 6 comments

Projects

None yet

6 participants

@hayd
Contributor
hayd commented Jan 15, 2013

link to #1651

Saving a multiindex column to_excel saves a sparse index.

Migrated from this StackOverflow question, with a smaller DataFrame.

In [1]: m = MultiIndex.from_tuples([(1,1),(1,2)], names=['a','b'])

In [2]: df = DataFrame([[1,2],[3,4]], columns=m)

In [3]: df
Out[3]: 
a  1   
b  1  2
0  1  2
1  3  4

In [4]: df.to_excel('test.xls')

Saves the xls:

    1.1 .2
0   1   2
1   3   4

This differs from how to_csv (which is not sparse):

,"(1L, 1L)","(1L, 2L)"
0,1,2
1,3,4
@joeb1415

Both to_excel and to_csv should allow a multiindex on the columns to print on multiple rows

@jreback
Contributor
jreback commented Mar 22, 2013

I guess then read_csv would have to take a list for the header argument to reconstruct the mi

@y-p
Contributor
y-p commented Mar 22, 2013

#2478, this is already hiding in the codebase, just needs some TLC.

@jreback
Contributor
jreback commented Sep 21, 2013

@hayd @jtratner IIRC this should still be open, right?

@jtratner
Contributor

yes, definitely.

@jmcnamara
Contributor

I think that has been fixed by #5423:

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')

Output:

screenshot

Can we close this?

@jreback jreback closed this Nov 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment