我的任务是编写一个 2D 数组,这将允许我反复循环该行并将单元格存储在一个 5 长度的数组中。我需要帮助的是如何创建它,以便它不断循环直到达到最后 5 个值并存储这些值。
例如,我的 .csv 文件中有 6 行整行
line = "1,9/20/2012, 48.019,34.888,37.334,35.425,36.69,38.916,36.837,39.212,37.528,37.404"
line = "1,9/20/2012, 38.019,54.888,36.334,35.425,36.69,38.916,36.837,39.212,37.528,37.404"
line = "1,9/20/2012, 28.019,31.888,56.334,33.825,36.69,38.916,36.837,39.212,37.528,37.404"
line = "1,9/20/2012, 48.019,34.888,37.334,35.425,36.69,38.916,36.837,39.212,37.528,37.404"
line = "1,9/20/2012, 38.019,54.888,31.334,37.425,33.69,38.916,36.837,39.212,37.528,37.404"
line = "1,9/20/2012, 28.019,31.888,56.334,33.825,36.69,38.916,36.837,39.212,37.528,37.404"
我已将脚本设置为跳过前 2 个值 [1,9/20/2012]
然后我将它们分开,这意味着前 5 个值是htr1
和第二个htr2
[ 48.019,34.888,37.334,35.425,36.69]
[38.916,36.837,39.212,37.528,37.404]
所以基本上我需要帮助的是获取列中的最后 5 个值并将它们存储在 python 中的数组或列表中。例如:
htrA[38.019,28.019,48.019,38.019,28.019]
htrB[36.334,56.334,37.334,31.334, 56.334
这是我到目前为止的代码
inFile = open("input_test.csv", "r")
outFile = open("results.txt", "w")
#To reliably determine steady state temperature average fifoSize last temperature readings
fifoSize = 5 #last fifoSize to average to get final temperature
bufFifo = FiFoBuf(fifoSize)
#Write Header
#outFile.write('Test Name,X+ avg,X+ std,X+ count,X- avg,X- std,X- count,X angle,Y+ avg,Y+ std,Y+ count,Y- avg,Y- std,Y- count,Y angle\n')
for line in inFile:
print line
#Characters of each line as list - items that were separated by commas
list = line.rstrip().replace(' ','').split(',')
list = list[2:] #remove index and date code (1st 2 items of list)
htr1 = list[0:5] #1st heater temperatures
htr2 = list[6:10] #2nd heater temperatures
print "\nhtr1: "
print htr1
print "\nchDeviation(htr1): "
print chDeviation(htr1)
avg()
#printStats()
inFile.close()
outFile.close()