I have an issue with my code. I am using ArcMap 10.8 and I am trying to create a sequence of numbers, taking into account one sorted field (the field "Latitude"). My code is the following one:
mxd = arcpy.mapping.MapDocument("Operating.mxd") #Pre-Logic Script Code: Set the mxd to be used`
lr=arcpy.mapping.ListLayers(mxd)[0] #Specify that the target layer is the first layer in the table of conten
tbl=arcpy.da.TableToNumPyArray(lr,("Label","Latitude"))
bs=sorted(tbl,key=lambda x: x[1])
aDict={}
for i,row in enumerate(bs):
aDict[row[0]]=i+1
def sortSeq(Label):
return aDict[Label]
sortSeq(!Label!) #Expression #to run the code, the following goes in the expression window`
Despite that the first time the code worked, when I repeated the process, it gives me an error that refers to the following (attached screenshot).