Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting header row from numpy.genfromtxt

Tags:

python

numpy

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?

like image 606
zelinka Avatar asked Oct 10 '13 17:10

zelinka


1 Answers

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')
like image 155
unutbu Avatar answered Sep 28 '22 06:09

unutbu