Problem printing column headers

9 views
Skip to first unread message

Richard Stanton

unread,
May 21, 2013, 12:46:48 PM5/21/13
to pyd...@googlegroups.com
Using today's development version, I wanted to print the column headers of
a dataframe, so tried the following:

df = DataFrame({'A' : [1,2,3], 'B' : [4,5,6]})
print df.columns.tostring()

This looked like it ought to work, and didn't complain I was asking it to
do something illegal, but produced garbage. Bug or user error?






Jeff

unread,
May 21, 2013, 12:56:34 PM5/21/13
to pyd...@googlegroups.com
tostring is not really a public method
 
In [1]: df = DataFrame({'A' : [1,2,3], 'B' : [4,5,6]})

In [2]: df.columns
Out[2]: Index([u'A', u'B'], dtype=object)

# returns the repr
In [3]: str(df.columns)
Out[3]: "Index([u'A', u'B'], dtype=object)"
 
# a list
In [4]: df.columns.tolist()
Out[4]: ['A', 'B']
 
# they act like a list
In [6]: ','.join(df.columns)
Out[6]: 'A,B'
Reply all
Reply to author
Forward
0 new messages