kwilli74

Update Cursor to Calculate Field

Discussion created by kwilli74 on Dec 7, 2013
Latest reply on Dec 7, 2013 by kwilli74
I'm trying to use an update cursor to calculate a field. Basically, I'm trying to avoid division by 0 by looking in row[0] and see if it's 0. My code thus far is:

import arcpy
fc="C:/Temp/crimeGrid.shp"
fields="'MEAN_GRIDC', 'SUM_Join_C', 'crimeRate')
with arcpy.da.UpdateCursor(fc,fields) as cursor:
    for row in cursor:
        if (row[0] > 0):
            row[2] = row[1]/row[0]
        else:
            row[2] = 0
        cursor.updateRow(row)


Any ideas or help on what I'm missing? I presume that it's the calculation aspect of my code.

Outcomes