我正在尝试使用带有标题名称和非同质数据类型的 numpy genfromtxt 导入数据。每次我运行程序时,我都会收到错误:
Traceback (most recent call last):
raise ValueError(errmsg)
ValueError: Some errors were detected !
Line #8 (got 6 columns instead of 1)
Line #9 (got 6 columns instead of 1)
Line #10 (got 6 columns instead of 1)
Line #11 (got 6 columns instead of 1)
Line #12 (got 6 columns instead of 1)
我已经解决了这个问题 ,但它并没有解决我的问题。这是一个非常简单的问题,但我不知道出了什么问题。代码和数据包括:
代码
import numpy as np
data = np.genfromtxt('Data.dat', comments='#', delimiter='\t', names=True, dtype=None).transpose()
print data
制表符分隔的数据
# -----
# -----
# -----
# -----
# -----
# -----
# -----
column_1 column_2 column_3 column_4 column_5 column_6
1 2 3 A 1 F
4 3 2 B 2 G
1 4 3 C 3 H
5 6 4 D 4 I
更新
简而言之,我需要一种将skip_header之后的第一个有效行转换为具有可选参数names=True的第一个未注释的有效行的方法。