import arcpy table = 'some_table' last_val = None count = 0 cursor = sorted(arcpy.da.UpdateCursor(table, ['PASS_NUM', 'TPN'])) for row in cursor: if row[0] == last_val: row[1] = count elif row[0] != last_val: count += 1 row[1] = count last_val = row[0] else: pass cursor.updateRow(row)