I have a large polygon dataset (26,000) records with numerous attributes columns. I wish to calculate the percentile rank of each attribute. Say I have population_density in an attribute, is there a simple formula to assign a rank in another attribute field on the percentile score of the value in the first attribute column (pop density)?


You can do this using arcpy in conjunction with numpy:

import arcpy
import numpy as np

input = "c:/data/usa.gdb/USA/counties"
arr = arcpy.da.FeatureClassToNumPyArray(input, ('population_density'))

##to create 3 rank for example
p1 = np.percentile(arr, 33)  # rank = 0
p2 = np.percentile(arr, 67)  # rank = 1
p3 = np.percentile(arr, 100)  # rank = 2

#use cursor to update the new rank field
with arcpy.da.UpdateCursor(input , ['population_density','PerRank']) as cursor:
    for row in cursor:
        if row[0] < p1:
            row[1] = 0  #rank 0
        elif p1 <= row[0] and row[0] < p2:
             row[1] = 1
             row[1] = 2


Just modify the code to adapt to your data and change the number of ranks as needed.

  • 1
    And in case the OP is unfamiliar with arcpy, this code can be entered in the Python window in ArcMap, or saved as a standalone script. It won't work with the Field Calculator. – nmpeterson Jan 31 '15 at 17:16

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.