Is there any way we can select top 500 values in attribute table? I tried by sorting area field ascending/descending... but I can't count big numbers to select. In microsoft excell we can do know, similarly in arcgis, is there any code to keep in attribute selection ??


I think this logic should work.

Step 1. cursor through the table and populate an array of the AREA values.

Step 2. sort the array by AREA.

Step 3. Find out the 500th largest AREA value.

Step 4. Select the table by attribute where AREA >= the 500th largest value.

  • I already mentioned this in my question that I did this. But how can we count very big numbers like "5896" from the attribute table? Its a hectic task. So I want a code or logic to include in attribute table so that I can avoid counting rows... it should be generic value may be 10,50,4567 or 339877.... Jul 6 '12 at 4:55

A non-programmable way to do this would be to sort your table as you have done, and then just go directly to the nth record that you want (by manually typing the value at the bottom of the attribute table). Once you get the field value for the nth value, just do step 4 in dklassen's first post.


Perhaps I don't understand your question, but I am not sure why you are counting these values. Let your script do that.

e.g. In python

import arcpy

myarray = []

cur = arcpy.SearchCursor("MYSHAPEFILE")

for row in cur:


mysortedarray = sorted(myarray)

value500 = mysortedarray[-500]

Then you can select by attribute using this value.

  • Thanks for response. I really need your help in this to implement in arcgis 9.3/10 and check as I am very poor in programming. My aim is to select my attributes which are "top XXXX" (any number). Jul 6 '12 at 5:18
  • The above should work - simply replace the shapefile name and 500 number with your values and then add the arcpy.SelectByAttribute_management() syntax and you should get your answer.
    – dklassen
    Jul 6 '12 at 5:21
  • Be careful with the above code, it wont work because the last two lines have an extra space in front of them. They shouldn't be indented. I would have edited it, but SE wont let me make edits which are less than 6 non-space characters.
    – Fezter
    Jul 6 '12 at 6:13
  • I fixed the indentation - this forum is not the best for typing out code. But anyways, this is just an example of what can be done, not necessarily the best/most efficient way.
    – dklassen
    Jul 6 '12 at 15:28

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.