Request: Multi-line header for to_csv when column is MultiIndex · Issue #1651 · pandas-dev/pandas (original) (raw)
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