Reputation: 3919
Suppose that I use genfromtxt to create a <type 'numpy.ndarray'>
.
data = np.genfromtxt("test.txt",dtype=None,delimiter=',',names=True)
This results in:
array((500, 501, 502, 503, 504, 504, 504), dtype=[('ColumnName1', '<i8'), ('ColumnName2', '<i8'), ('ColumnName3', '<i8'), ('ColumnName4', '<i8'), ('ColumnName5', '<i8'), ('ColumnName6', '<i8'), ('ColumnName7', '<i8')])
What I would like to know is how to retrieve the column names? data.dtype
doesn't seem to be getting me there.
Upvotes: 1
Views: 2472
Reputation: 26333
this seems to be working, as to the results i get with data.dtype.names
>>> import numpy as np
>>> data=np.array((500, 501, 502, 503, 504, 504, 504),
dtype=[('ColumnName1', '<i8'), ('ColumnName2', '<i8'),
('ColumnName3', '<i8'), ('ColumnName4', '<i8'), ('ColumnName5', '<i8'),
('ColumnName6', '<i8'), ('ColumnName7', '<i8')])
gives
>>> data.dtype.names
('ColumnName1', 'ColumnName2', 'ColumnName3',
'ColumnName4', 'ColumnName5', 'ColumnName6', 'ColumnName7')
Upvotes: 3
Reputation: 60147
data.dtype
is exactly where you should be looking. Where else? You want:
data.dtype.names
Upvotes: 2