我有一些看起来像this的数据。
我需要调用第一列和第二列(时间和毫升)。
我已导入所有相关内容。
这是我要处理的代码部分:
time = []
d180= []
a = np.arange(0.0,5320.0,1.0)
b = np.array(a,dtype=float)
file = open(filename)
for line in file:
for i in a:
if line[0] == 'P':
False
elif line[0] == 'T':
False
else:
fields = (line.strip()).split('\t')
time.append(fields[0])
d180.append(fields[1])
file.close()
time = np.array(time,dtype=float)
d180 = np.array(benthic,dtype=float)
plt.figure()
plt.plot(time,d180)
plt.xlabel('Time')
plt.ylabel('ml')
plt.show()
现在,我收到d180.append(fields [1])的索引错误“列表超出范围”。
我应该提到numpy数组b是以前尝试这种方法时遗留下来的:
for i in len(b):
for line in file:
if float(line[0]) == b[i]
fields = (line.strip()).split('\t')
time.append(fields[0])
d180.append(fields[1])
但这可能不可行,原因可能有几个,主要是因为无法将“ P”或“ T”转换为浮点数。
最后,数据文件是.txt文件可能与之相关。