A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/1651 below:

Multi-line header for to_csv when column is MultiIndex · Issue #1651 · pandas-dev/pandas · GitHub

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4