使用np.genfromtxt()从文本文件中获取数据受文件中列数的限制?

2024-03-29 08:44:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用np.genfromtxt要从文本文件中获取数据,但我无法理解此错误消息:

data = np.genfromtxt('ctr_tr3.txt', skip_header=2, names=True)

a=data['PO4']

Traceback (most recent call last):
  File "C:\EclipseIndigoWorkspace\W2\src\Import.py", line 55, in <module>
    data = np.genfromtxt('ctr_tr3.txt', skip_header=2, names=True)
  File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 1560, in genfromtxt
    raise ValueError(errmsg)
ValueError: Some errors were detected !
    Line #4 (got 10 columns instead of 11)
    Line #5 (got 10 columns instead of 11)
    Line #6 (got 10 columns instead of 11)
    Line #7 (got 10 columns instead of 11)
    Line #8 (got 10 columns instead of 11)
    Line #9 (got 10 columns instead of 11)

Tags: columnsoftxttruedatanamesnpline