Loading text file containing both float and string using numpy.loadtxt

后端 未结 2 924
走了就别回头了
走了就别回头了 2020-12-02 23:28

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.         


        
2条回答
  •  醉梦人生
    2020-12-02 23:55

    It seems that keeping the numbers and text together has been causing you so much trouble - if you end up deciding to separate them, my workaround is:

    values = np.loadtxt('data', delimiter=',', usecols=[0,1,2,3])
    labels = np.loadtxt('data', delimiter=',', usecols=[4])
    

提交回复
热议问题