我有一个 txt 文件,格式如下(简体):
date this that other
2007-05-25 11:00:00 10 20 30
2007-05-25 11:10:00 15 18 30
2007-05-25 11:20:00 10 27 30
2007-05-25 11:30:00 20 35 30
2007-05-25 11:50:00 30 20
2007-05-25 12:00:00 30 13
2007-05-25 12:10:00 30 13
第一个原始字符串是定义它们上方的列的字符串。第一列很明显是时间。还可以观察到一些值丢失。我不想删除缺少某些值的行。因为我想稍后对这些数据进行一些计算,所以我想使用 numpy 通过以下方式导入该数据numpy.loadtxt
:
data = numpy.loadtxt('data.txt')
ValueError: could not convert string to float: b'date'
由于第一个原始数据,它给出了一个错误。使用:
data = numpy.genfromtxt('data.txt')
对许多行给出错误Line #51028 (got 38 columns instead of 37)
,这是因为缺少某些值。我应该尝试什么?