I have a shapefile with a field attribute called "Value"
.
I would like to find the min
and max
in this field and
- if
max-min > 0.014
return1
(orYes
) - if
max-min < 0.014
then return2
(orNo
)
in the field called "YES_NO"
.
I have a shapefile with a field attribute called "Value"
.
I would like to find the min
and max
in this field and
max-min > 0.014
return 1
(or Yes
)max-min < 0.014
then return 2
(or No
)in the field called "YES_NO"
.
Use the da.SearchCursor to find min, max and diff. Update field with the UpdateCursor:
import arcpy
fc = r'C:\data.gdb\featureclass'
fields = ['Value','YES_NO']
all_rows = [i[0] for i in arcpy.da.SearchCursor(fc,fields[0])]
min_val = min(all_rows)
max_val = max(all_rows)
difference = max_val-min_val
if difference > 0.014:
newval = 1
elif difference <= 0.014:
newval = 2
else:
newval = 3
with arcpy.da.UpdateCursor(fc,fields[1]) as cursor:
for row in cursor:
row[0] = newval
cursor.updateRow(row)