Reputation: 289
I'm currently working on a dataset that consists of the following data:
paper_id, word_attributes, class_label
Now there are a total of 3700 word_attributes columns representing a binary value. Is there a method in python using which I could assign the column headers? Thanks.
Upvotes: 1
Views: 99
Reputation: 58965
You can perhaps read the csv file using:
a = np.genfromtxt(filename, delimiter=',', dtype=None, names=True)
it will create a numpy.recarray
where each column can be called by a key, like a['paper_id']
. When dtype=None
, "the dtypes will be determined by the contents of each
column, individually".
EDIT: as suggested by @askewchan, you have to pass names=True
to keep the original names for the csv columns.
Upvotes: 2