This question already has an answer here:

I have an Attribute table with 151823 rows. I want to cut off the upper and lower 5% of the data so I sorted the Value field ascendingly but now I am not able to select the first and the last 7591 entries which would be the 5%, as the FID is not in the right order anymore. I tried it with a new field (NewID) with the intention to just have a new sequential numbering but this did not work. I used the script presented here

Sorting feature class to calculate sequential ID field using ArcGIS Field Calculator?

Does anyone know a simple solution?

marked as duplicate by FelixIP, BERA, whyzar, aldo_tapia, Antonio Falciano Nov 21 '17 at 10:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • why did the NewID field ordering not work? – NULL.Dude Nov 20 '17 at 16:26
  • This looks like a possible duplicate of gis.stackexchange.com/q/262299/115 – PolyGeo Nov 20 '17 at 19:55
  • You should of use procedure explained in 2nd answer, not what you call script in 1st. – FelixIP Nov 21 '17 at 4:28

I think the best solution is scripting.It's versatile.

Create a new field with "Long Integer" type.I named it to "SecondField".

Row count = 151823

First 5% finished to 7591 row (I rounded it)

Last 5% started from 144232 row

In this code set your workspace. example:

arcpy.env.workspace = "D:/test.gdb"

Set Layer name after "fc= " :

fc= "Mylayer"

Set field names in the bracket of "UpdateCursor". The id field name and the new field name respectively.

The First 5% and last 5% will be write in this new field.Then you can select records and extract them.

import arcpy
arcpy.env.workspace = r"...\Geodatabase.gdb"
fc = "YourlayerName"
sorted_table = arcpy.Sort_management(fc,"fclyr","NewID DESCENDING")
with arcpy.da.UpdateCursor(sorted_table,["NewID","SecondField"]) as cur:
    for row in cur:
        if row[0]< 7591 or row[0]> 144232:           

            row[1] = 1
del row 
del cur

Note: There are some solutions to calculate the number of rows and first-last 5% numbers automatically.I want to give a simple example for you then i hardcode these numbers.

  • It is not a solution asker seeking, because no sorting involved. – FelixIP Nov 21 '17 at 4:25
  • I forgot sorted field. I edited my answer. – BBG_GIS Nov 21 '17 at 8:10
  • 1
    Thank you, I finally solved it using the posted links. But really thanks for your efforts. – Thessla Nov 21 '17 at 8:15
  • Well mark it as correct answer then. – FelixIP Nov 21 '17 at 8:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.