3

With arcpy, I want to calculate the mean value of a specific field in a shapefile and print the resulting value for the user. I use the Summary Statistics tool and it works, but the resulting value is stored in a table at a specific path, but how can I access the calculated value with python?

Here is my code. It will only output the path to the table, but I need the calculated value.

stats = arcpy.Statistics_analysis(myshapefile, "G:/temp/stats", [[field, "MEAN"]])
arcpy.AddMessage(stats.getOutput(0))

1 Answer 1

2

The way I would recommend to access the contents of a table is by using arcpy.da.SearchCursor() to read it:

SearchCursor establishes read-only access to the records returned from a feature class or table.

Returns an iterator of tuples. The order of values in the tuple matches the order of fields specified by the field_names argument

The asker also:

found a useful function on this website: https://arcpy.wordpress.com/2012/02/01/calculate-a-mean-value-from-a-field/

which groups the Summary Statistics with a Search Cursor to read its output and return the Mean value from a field.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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