Python 3.x 如何正确指定dtype str?

Python 3.x 如何正确指定dtype str?,python-3.x,numpy,genfromtxt,Python 3.x,Numpy,Genfromtxt,文件为实用程序.dat Name D L J H E M RF AF line1 150 4.5 2.0 150 2 Copper 0.8 true line2 140 4.5 2.0 140 2 Aluminium 0.8 true 我的脚本是script.py import numpy configName = "utility.dat" lines = numpy.genfromtxt(configName,

文件为实用程序.dat

Name    D   L   J   H   E   M   RF  AF
line1   150 4.5 2.0 150 2   Copper  0.8 true
line2   140 4.5 2.0 140 2   Aluminium   0.8 true
我的脚本是script.py

import numpy
configName = "utility.dat"
lines = numpy.genfromtxt(configName,
                         skip_header=1,
                         dtype=(str, float, float, float, float, float, str, float, bool))

print(lines[0])
我的结果是

('',  150.,  4.5,  2.,  150.,  2., '',  0.8,  True)

Process finished with exit code 0
现在,如何正确指定dtype?因为我不想给出像“S12”这样的尺寸,因为我不可能知道它能有多大。我也不想使用dtype=None


还有其他解决方案吗?

因为我无法通过NumPy实现这一点,所以我搬到了Pandas,它对我很有效

我对Python还不熟悉,所以还在学习,但我的想法是,如果我想要一个包含浮点、字符串、整数的数据表,我最好使用Pandas,如果我的纯表主要是浮点和整数,我最好使用NumPy


现在熊猫为我工作,所以继续前进。谢谢

所以您知道一个解决方案,即使您不想使用它。另一个是
dtype=None
。我也不想使用
dtype=None
还有其他方法吗?编写您自己的csv加载器。只需使用
usecols
初步加载字符串列,就会告诉您正确的
S
长度。