2010-10-27 47 views
0

我需要迭代字段並計算另一列中的值與少數列組的總和。ArcGIS python 2.5腳本 - 通過迭代記錄集創建一個統計表

對於離基表

C1 C2 C3 C4 C5 
a1 2 3 4 q 
a1 4 5 7 a 
a2 34 56 6 e 
a2 4 5 5 5 
a3 3 3 3 4 
a3 3 3 3 3 

結果表應該是

c2 c3 c4 
a1 6 8 11 
a2 38 61 11 
a3 6 6 6 
    50 75 28 

我能夠迭代字段,以獲取每個字段的值,但被困在創建二維結果格式矩陣。我正在研究2維數組來實現這種情況。從這裏很多的假設,因爲這個問題是相當非特異性

+0

是你列始終排序? – SilentGhost 2010-10-27 09:35:58

+0

「C1-5」和「a1-3」是實際數據的一部分,還是隻是爲了澄清? – 2010-10-27 09:36:58

回答

0

工作...

# table containing only the actual data 
table = [[2,3,4,"q"],[4,5,7,"a"],[34,56,6,"e"],[4,5,5,5],[3,3,3,4],[3,3,3,3]] 
result = [] 

# iterate through table[0/2/4/...] zipped together with table[1/3/5/...] 
for (row1, row2) in zip(table[::2], table[1::2]): 
    # add the first three elements of each row and append the results to our result 
    result.append([c1+c2 for c1,c2 in zip(row1[:3], row2[:3])]) 

print(result) 

輸出

[[6, 8, 11], [38, 61, 11], [6, 6, 6]]