我有一个包含int,string和float的.txt文件。如何在保留字符串的同时将此.txt文件作为矩阵导入?
数据集包含:
16 disk 11 10.29 4.63 30.22 nan
79 table 11 20.49 60.60 20.22 nan
17 disk 11 22.17 0.71 10.37 nan
我用过:
data=np.loadtxt("/home/Desktop/dataset.txt", delimiter=',')
结果是:
items = [conv(val) for (conv, val) in zip(converters, vals)]
ValueError: could not convert string to float: disk
在我用过的另一次尝试中:
data = np.genfromtxt('/home/Desktop/dataset.txt', delimiter=",")
结果是:
16.0 nan 11 10.29 4.63 30.22
79.0 nan 11 20.49 60.60 20.22
17.0 nan 11 22.17 0.71 10.37