flederfauz

Ranking Fields

Discussion created by flederfauz on Jun 8, 2011
Latest reply on Jun 9, 2011 by tlsilveus
Hi!

What I am looking for is giving the FieldA a Rank depending on the values in FieldB. I would like to end up with sth. like this. Can i do this easy in the field calculator?
Rank     orig. Value
1           5
2           7
3           14
4            23

in python i did it like this:
import arcpy, numpy, os
from arcpy import env


import arcpy, numpy, os
ShapeName=arcpy.GetParameterAsText(0)
Field=arcpy.GetParameterAsText(1)
RankField=arcpy.GetParameterAsText(2)
rows = arcpy.SearchCursor(ShapeName)
d=[]
for row in rows :
    FieldValue=row.getValue(Field)
    d.append(FieldValue)
d.sort()
arcpy.AddMessage(d)
del rows
rows2 = arcpy.UpdateCursor(ShapeName,"","",RankField,"")
row2= rows2.next() 
while row2:
    x=0
    for i in d:
        y=d[x]
        if row2.getValue(Field)==y:
            rank2=d.index(y)
            rank=rank2+1
            row2.setValue(RankField, rank) 
            rows2.updateRow(row2)
        x=x+1
    row2 = rows2.next()
    
del rows2



Thanks for any help

Outcomes