17

I did this call:

data = numpy.genfromtxt('grades.txt', dtype=None, delimiter='\t', names=True)

How do you get a list of the column names?

1 Answer 1

21

The column names can be found in

data.dtype.names

For example,

In [39]: data
Out[39]: 
array([('2010-1-1', 1.2, 2.3, 3.4), ('2010-2-1', 4.5, 5.6, 6.7)], 
      dtype=[('f0', '|S10'), ('f1', '<f8'), ('f2', '<f8'), ('f3', '<f8')])

In [40]: data.dtype
Out[40]: dtype([('f0', '|S10'), ('f1', '<f8'), ('f2', '<f8'), ('f3', '<f8')])

In [41]: data.dtype.names
Out[41]: ('f0', 'f1', 'f2', 'f3')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.