Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

tkf opened this issue Jul 19, 2012 · 3 comments
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@tkf
Copy link
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
@joeb1415
Copy link

+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

@feilchenfeldt
Copy link

+1 for this and Issue #3141

@jreback
Copy link
Contributor

jreback commented May 19, 2013

closed via #3575

@jreback jreback closed this as completed May 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Data IO issues that don't fit into a more specific label Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

4 participants