Generate basic summary statistics for a field in a feature class using ArcPy
import arcpy
import statistics
def basic_fc_stats(fc, field):
field_vals = []
total = 0
row_count = 0
with arcpy.da.SearchCursor(fc, field) as cursor:
for row in cursor:
total = total + row[0]
row_count+=1
field_vals.append(row[0])
mean = statistics.mean(field_vals)
median = statistics.median(field_vals)
stdev = statistics.stdev(field_vals)
summary = {'sum': total, 'row_count': row_count, 'mean': mean, 'median': median, 'stdev': stdev}
return summary
Generating summary statistics in ArcGIS is a bit more complicated than it needs to be. The Summary Statistics tool requires that you return your output to some sort of tabular data file. Sometimes you just need to see the number really quickly or see how they change if you filter the data differntly. This is function is the beginnings of a simple tool to generate summary statistics for a given field in a feature class. The function returns a dictionary containing the number of entries, the sum of the entries, and mean/median/standard deviatation value of the entries for the inputed field.