Numbering of records that have same ID with sequential numbers that start from zero,

3044
2
Jump to solution
11-12-2015 09:55 PM
JamalNUMAN
Esteemed Contributor

Numbering of records that have same ID with sequential numbers that start from zero,

For example, in the screenshot below, 4 buildings take (42/1/Beituniya) as their ID. What I need is to add new field (BuildingNumber) at which I want to stick sequential numbers for these buildings.

Clip_179.jpg

How this might be performed?

Thank you

Best

Jamal

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
0 Kudos
1 Solution

Accepted Solutions
LukeSturtevant
Occasional Contributor III

You could try an update cursor like so:

import arcpy

getMax = max([row[0] for row in arcpy.da.SearchCursor("TestPoints","FREQUENCY")]) +1

for i in range (getMax):
     j = 0
     with arcpy.da.UpdateCursor("TestPoints",["FREQUENCY","BuildingNumber"]) as update:
         for row in update:
             if row[0] == i:
                 row[1] = j
                 j += 1
             else:
                 j = 0
             update.updateRow(row)

View solution in original post

2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Moved to Geoprocessing

Use the GeoNet Community Structure​ for better placement of questions.

0 Kudos
LukeSturtevant
Occasional Contributor III

You could try an update cursor like so:

import arcpy

getMax = max([row[0] for row in arcpy.da.SearchCursor("TestPoints","FREQUENCY")]) +1

for i in range (getMax):
     j = 0
     with arcpy.da.UpdateCursor("TestPoints",["FREQUENCY","BuildingNumber"]) as update:
         for row in update:
             if row[0] == i:
                 row[1] = j
                 j += 1
             else:
                 j = 0
             update.updateRow(row)