How Can I Find The Missing Sequence Number in a Field in ArcGIS I have thousand numbers on that field ? I have ArcGIS 10.8
Solved! Go to Solution.
You can do it with a little Python script:
fc = "TestPolygons" # path the the feature class or name of the layer
field = "IntegerField1"
# get a set of values in the field
values = {row[0] for row in arcpy.da.SearchCursor(fc, [field])}
# get a set of the complete range
complete_values = set(range(min(values), max(values)))
# the difference between these sets are the missing numbers
missing_values = complete_values - values
print(sorted(missing_values))
fc = "TestPolygons" # path the the feature class or name of the layer
field = "IntegerField1"
group_field = "TextField1"
# read the fc
data = [row for row in arcpy.da.SearchCursor(fc, [group_field, field])]
# iterate over the groups
groups = {d[0] for d in data}
for g in sorted(groups):
# get the values in that group
values = {d[1] for d in data if d[0] == g}
# get a set of the complete range
complete_values = set(range(min(values), max(values)))
# the difference between these sets are the missing numbers
missing_values = complete_values - values
print("Missing values in group {}: {}".format(g, sorted(missing_values)))
You can do it with a little Python script:
fc = "TestPolygons" # path the the feature class or name of the layer
field = "IntegerField1"
# get a set of values in the field
values = {row[0] for row in arcpy.da.SearchCursor(fc, [field])}
# get a set of the complete range
complete_values = set(range(min(values), max(values)))
# the difference between these sets are the missing numbers
missing_values = complete_values - values
print(sorted(missing_values))
what should I change in your Python script to work , I create field test to run your Python script but it does not work , I want to know the missing number in field parcel ….I need more details!!!
The script is meant to be run in the Python Window, not in the Fieled Calculator.
Ok now its work …. but can we make another change in the python script to let him give us the missing number in group A and the missing number in group B , because the missing number in group A is different than the missing number in group B.
fc = "TestPolygons" # path the the feature class or name of the layer
field = "IntegerField1"
group_field = "TextField1"
# read the fc
data = [row for row in arcpy.da.SearchCursor(fc, [group_field, field])]
# iterate over the groups
groups = {d[0] for d in data}
for g in sorted(groups):
# get the values in that group
values = {d[1] for d in data if d[0] == g}
# get a set of the complete range
complete_values = set(range(min(values), max(values)))
# the difference between these sets are the missing numbers
missing_values = complete_values - values
print("Missing values in group {}: {}".format(g, sorted(missing_values)))
Thank You Very Much For Your Great Solution