I have a text file, data.txt, which contains:
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
5.8,2.7,4.1,1.0,Iris-versicolor
6.2,2.2,4.5,1.5,Iris-versicolor
6.4,3.1,5.5,1.8,Iris-virginica
6.0,3.0,4.8,1.8,Iris-virginica
How do I load this data using numpy.loadtxt() so that I get a NumPy array after loading such as [['5.1' '3.5' '1.4' '0.2' 'Iris-setosa'] ['4.9' '3.0' '1.4' '0.2' 'Iris-setosa'] ...]?
I tried
np.loadtxt(open("data.txt"), 'r',
dtype={
'names': (
'sepal length', 'sepal width', 'petal length',
'petal width', 'label'),
'formats': (
np.float, np.float, np.float, np.float, np.str)},
delimiter= ',', skiprows=0)