I am very rusty/inexperienced in Python.
I would like to create a more compact script that prints min and max values of each numeric field from a feature class. Right now I have the code below repeated for each field that contains numeric values.
How would I code this to identify if a field has numeric values and then print the min and max values to the python shell or even better to a .csv/text file?
import arcpy
data = "C:/Workfolder/Input.gdb/FeatureClass"
listname = []
cursor = arcpy.da.SearchCursor(data, "field1")
for row in cursor:
listname.append(int(row[0]))
print 'Field1_min, {0}'.format(min(listname))
print 'Field2_max, {0}'.format(max(listname))
Best Answer
I think one of the efficient options would be using
where
andsql_clause
arguments ofarcpy.da
, for example:This also makes sure the only non-NULL values are processed (where clause).