1

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 return 1 (or Yes)
  • if max-min < 0.014 then return 2 (or No)

in the field called "YES_NO".

enter image description here

5
  • 1
    have you already seen these articles: Determining Min/Max values from feature class using ArcPy?, arcpy min/max/unique values of a field?
    – Taras
    Nov 7, 2018 at 8:00
  • So all rows will have yes or all will have no?
    – BERA
    Nov 7, 2018 at 8:07
  • It is unclear. Do you want to know if the difference between two successive rows more or less than 0.014, or just max - min values in the Value field more or less than 0.014? Please explain in your question.
    – ahmadhanb
    Nov 7, 2018 at 8:10
  • no, can be completely 1 or completely 2
    – Anahita Kp
    Nov 7, 2018 at 8:11
  • in this example the max = 1.1255 and min = 1.0852. max - min = 0.040 so its > 0.014. so the field YES-NO is filled completely by 1
    – Anahita Kp
    Nov 7, 2018 at 8:15

1 Answer 1

2

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.