Need help returning total sum of table field

Discussion created by michelle.pruse on Apr 4, 2017
Latest reply on Apr 4, 2017 by iamurray

Hi I'm having trouble returning the total sum of my value field to my updateFC for each row within the update feature class. Any pointers would be appreciated.



import arcpy
import numpy as np
arcpy.env.workspace = 'C:\Users\michellep\Documents\project.gdb'

print "Arcpy & Numpy Successfully Imported"
print "Start Processing"
start = time.time()

sourceFC = 'Test_Group'
sourceFields = ['ID_Data', 'KV', 'AV', 'Total']
pc = r'C:\Users\michellep\Documents\Data\Table.dbf'
PCFields = ['AV', 'KV', 'WV', 'B', 'kW', 'Value']

#create dict of test group

valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFields)}

#point to update FC test_group_1
updateFC = 'Test_Group_1'
updateFields = ['ID_Data', 'KV', 'AV', 'Total']

updateCursor = arcpy.da.UpdateCursor(updateFC, updateFields)
updatePC = arcpy.da.UpdateCursor(pc, PCFields)

for UpdateRow in updateCursor:
    keyValue = UpdateRow[0]
    if keyValue in valueDict:
        for row in updatePC:
            row[1] = valueDict[keyValue][1]
            row[0] = valueDict[keyValue][0]
            row[2] = row[1]/ row[0] * (row[3]/ row[0])
            row[5] = row[2] * row[4]
            arr = arcpy.da.TabletoNumPyArray(pc, "Value")
            arr.dtype = np.dtype(float)
            UpdateRow[3] = np.sum(arr)
            del row
        del UpdateRow

end = time.time()
processTime = end - start
print "Processing Completed - {:.1f} seconds".format(processTime)