Question

I want to convert a csv into a numpy array. The first row of the csv file contains the names / titles of the columns. But when I use genfromtxt with the names parameter set to true I still receive only a normal numpy array with a lot of NaN values. What did I forget?

numpy.genfromtxt("test.csv", names=True, delimiter=",")
array([[ NaN,  64.,  11., ...,  NaN,  NaN,  NaN],
       [ NaN,  64.,  11., ...,  NaN,  NaN,  NaN],
       [ NaN,  64.,  11., ...,  NaN,  NaN,  NaN],
       ..., 
       [ NaN,  64.,  11., ...,  NaN,  NaN,  NaN],
       [ NaN,  64.,  11., ...,  NaN,  NaN,  NaN],
       [ NaN,  64.,   5., ...,  NaN,  NaN,  NaN]])
Was it helpful?

Solution

You have to set the dtype to None:

numpy.genfromtxt("test.csv", names=True, delimiter=",", dtype=None)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top