AnsweredAssumed Answered

How can you calculate Q1,Q2,Q3, and IQR using ESRI?

Question asked by Dcamrine on Mar 18, 2016
Latest reply on Mar 18, 2016 by Dan_Patterson

I hope the answer does not require Geostatistical Analyst!


To calculate these statistical values you have to first sort the values by ascending order.


Q2 is the mean or the total number of values divided by two and it gives you the position of the value in terms of n. so if you had 100 values then median is the (value at position 50) plus the (value at position 51) divided by 2. If you had 101 values the median would be the value at position 51.


I have several hundred shape files with values that I want to apply this calculation to.


I would like to use a combination of python and model builder to calculate these, calculate and upper and lower "fence" and then find the values that are above and below these "fences".


I had the work flow all worked out! until I tried to create a new sequential number field based on the ascending sort.


I found this code:

def autoIncrement(start=0,step=1):
    while 1:
        yield i
incrementCursor = arcpy.UpdateCursor(table_name) #There is no guarantee of order here
incrementer = autoIncrement(10,2)
for row in incrementCursor:
    row.setValue(field, #Note use of next method


I changed table_name to "Name of shape file" with target field

I changed field to 'name of the field' in said shape file

selected the column in the open attribute table


When I pressed enter at the end of (row) it just went down one line..I pressed it again

and it went back to >>>


none of the rows were updated. I thought the cursor is what you have selected in your map document.

so I need to

1. Tell each shape file to sort the target values in ascending order (used sort tool with iterater in model builder)

2. create a script that populates a new field with sequential numbers based on the new sort.


Any help on this is much appreciated!