Search code examples
pythonnumpynp

np.genfromtxt error in python 3


When I use

dataset = np.genfromtxt(open('data/train.csv','r'), delimiter=',', dtype='f8,str')[1:]

I obtain this error

TypeError: must be str or None, not bytes

Could you help me to find the solution?


Solution

  • Do not use open within np.genfromtxt:

    dataset = np.genfromtxt('data/train.csv', delimiter=',', dtype='f8,str')[1:]