Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Update Cursor to Calculate Field

$
0
0
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:

Code:

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.

Viewing all articles
Browse latest Browse all 2485

Trending Articles