我的任務是編寫一個2D數組,它將允許我重複循環遍歷該行並將這些單元格存儲在一個5長度的數組中。我想要幫助的是如何創建它,以便它保持循環,直到達到最後5個值並存儲它們。在python中製作二維數組
因此,作爲一個例子,我在我的.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中使用rray或list。例如:
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()
所以這不起作用? –
不需要工作 – user1778360
您爲'htrB'顯示的值不是來自下一列,而是來自輸入數據之外的值。 – martineau