I need to calculate a sequential ID for unique values in a field. So, for the values in Field1, the sequential ID count should count all occurrences of that value, then restart the count for the next value. For the example below, column 1 contains the values to count, column 2 is what the sequential field result should look like.
My plan was to approach this with an update cursor and the classic autoIncrement code, but it calculated all rows in the table with a sequential ID. I know the if/else is the wrong approach, but I was hoping the autoIncrement would start over within each if statement. I'm guessing I need to get a count of the unique values in Field1, then somehow calculate the sequential ID on the row as it counts? I saw a collections.Counter example, but wasn't sure if that could be applied here.
table = table path fields = ('FIELD1,FIELD2') rec=0 def autoIncrement(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec = rec + pInterval return rec with arcpy.da.UpdateCursor(table, fields) as uc: for row in uc: if row == 'A': row = str(autoIncrement()) etc.