pandas column names to list
Or, you could try:
df2 = df.columns.get_values()
which will give you:
array(['q_igg', 'q_hcp', 'c_igg', 'c_hcp'], dtype=object)
then:
df2.tolist()
which gives you:
['q_igg', 'q_hcp', 'c_igg']
If you're just interested in printing the name without an quotes or unicode indicators, you could do something like this:
In [19]: print "[" + ", ".join(df) + "]"
[q_igg, q_hcp, c_igg, c_hcp]
Simple and easy way: df-dataframe variable name
df.columns.to_list()
this will give the list of the all columns name.
The list [u'q_igg', u'q_hcp', u'c_igg', u'c_hcp']
contains Unicode strings: the u
indicates that they're Unicode strings and the '
are enclosed around each string. You can now use these names in any way you'd like in your code. See Unicode HOWTO for more details on Unicode strings in Python 2.x.