numpy recfromcsv and genfromtxt skips first row of data file

io, numpy, python, scipy

Solution

The default first line of a csv file contains the field names. The function `recfromcsv` invoke `genfromtxt` with parameters `names=True` as default. It means that it read the first line of the data as the header.

Definition: http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html

You should write it before the array.

import numpy as np

filename = 'data.csv'
writer = open(filename,mode='w')
writer.write('first column,second column,third column\n')
writer.write('0,1.1,1.2\n1,2.1,2.2\n2,3.1,3.2')
writer.close()

data = np.recfromcsv(filename)
print data

Or use `recfromtxt` instead of `recfromcsv`.

Or overwrite the default name as

recfromcsv(filename, names=['a','a','a'])

Problem

numpy's recfromcsv skips the first line of my data. (Same thing for genfromtxt) ``` import numpy as np filename = 'data.csv' writer = open(filename,mode='w') writer.write('0,1.1,1.2\n1,2.1,2.2\n2,3.1,3.2') writer.close() data = np.recfromcsv(filename) print data ``` Is this a bug, or how can I load the data without loosing the first line?

Original source