I am having a problem with adding sequential numbers to the new column based on other sorted value. I would like to use 'Sort by' column to be able to generate numbers in the 'Required number'column.

I have a script listed below (Field calculator) that allows me to generate numbers in 'Script used' column. Unfortunately, the numbers start from 0 instead of 11.

mxd = arcpy.mapping.MapDocument("CURRENT")

tbl=arcpy.da.TableToNumPyArray(lr,("objectid","MapOrderNum"))#MapOrderNum is a field that you want to use to sorb by
bs=sorted(tbl,key=lambda x: x[1])
for i,row in enumerate(bs):
def sortSeq(objectid):
 return aDict[objectid]

sortSeq ( !OBJECTID!)

enter image description here

  • 2
    Try to use for i,row in enumerate(bs, 11) instead of for i,row in enumerate(bs) – ahmadhanb Jan 23 '19 at 11:48
  • Or return aDict[objectid]+11. You can use da.SearchCursor instead of TableToNumPyArray, not sure what will be faster: tbl = [i for i in arcpy.da.SearchCursor(lr, ["OID@","MapOrderNum"])]. Will be a list of tuples which you can sort the same way. – BERA Jan 23 '19 at 12:22