Request: Multi-line header for to_csv when column is MultiIndex #1651

Closed
tkf opened this Issue Jul 19, 2012 · 3 comments

Comments

Projects
None yet
4 participants
Contributor

tkf commented Jul 19, 2012

Having tuple as string in header line is not what I expected.
Any particular reason for this behavior?:

In [1]:
import pandas
import numpy
from itertools import product
df = pandas.DataFrame(numpy.random.randint(low=10, high=100, size=(2, 4)))
df.columns = pandas.MultiIndex.from_tuples(list(product('ab', 'xy')))
print df

    a       b    
    x   y   x   y
0  86  55  85  20
1  89  32  71  18

In [2]:
import sys
df.to_csv(sys.stdout, sep='\t')

    ('a', 'x')  ('a', 'y')  ('b', 'x')  ('b', 'y')
0   86  55  85  20
1   89  32  71  18

It would be nice if there is an option to output multi-line header with df.to_csv, like what print df or df.to_html does. Or even make it as default.

Also, header_format option to format would be nice, e.g.:

df.to_csv(sys.stdout, sep='\t', header_format='{0}.{1}')

    a.x a.y b.x b.y
0   86  55  85  20
1   89  32  71  18

+1.
With option to allow header as
a b
x y x y
0 86 55 85 20
1 89 32 71 18

or
a a b b
x y x y
0 86 55 85 20
1 89 32 71 18

+1 for this and Issue #3141

Contributor

jreback commented May 19, 2013

closed via #3575

jreback closed this May 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment