-1

I'm looking for advice about the ArcPy code necessary to find: the highest value, the minor value and the number of single values (not records) of a field in a table.

  • I tried to use the cursor but without resuts – Gianni May 3 '18 at 12:43
  • 2
    Please post the code you used for the cursor. Try adding print statements along the way to debug and let us know at what stage it is giving unexpected results. – smiller May 3 '18 at 12:44
2

There are a lot of useful examples posted on Esri's ArcGIS help pages.

For example, here's the code for finding unique values of a field using the search cursor.

import arcpy

fc = 'c:/data/base.gdb/well'
field = 'Diameter'

# Use SearchCursor with list comprehension to return a
# unique set of values in the specified field
values = [row[0] for row in arcpy.da.SearchCursor(fc, field)]
uniqueValues = set(values)
print(uniqueValues)

This was taken from Example 2 on the help pages for search cursor.

The rest are standard python functions -- e.g. len(uniqueValues), min(uniqueValues), max(uniqueValues).

| improve this answer | |
2
import arcpy
fc = r'C:\database.gdb\feature_class'
value_field = 'Values'

all_values = [i[0] for i in arcpy.da.SearchCursor(fc, value_field)]

print max(all_values) #max
print min(all_values) #min
print len(set(all_values)) #number of unique values
| improve this answer | |

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