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))
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 15, 2016 at 7:19

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.

answered Mar 15, 2016 at 7:41
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.