Identify duplicate records & increment

801
2
09-23-2012 10:40 PM
ChrisGraves
Occasional Contributor
Hey GIS Users,

I'm trying to identify duplicate records from a field and then change these records so they become unique by assigning at the end

of text string A,B,C, or 1,2,3 (eg F3241 A56_A or F3241 A56_1).

I would like to make the change in the field the records are stored in and not create another field. Also, I'm looking to perform this

as part of a bigger function using modelbuilder so would like to use field calculator or a python script so I can place it in the model.

I've attached a screenshot of the field & records I'm trying to identify & increment.

Any input into to this would be greatly appreciated.

Cheers,

Chris
Tags (2)
0 Kudos
2 Replies
ArkadiuszMatoszka
Occasional Contributor II
Hi,
I thing create dictionary with increment value would be simple and elegant solution. It will look something like:

import arcpy
import sys
in_table = sys.argv[1]
field = sys.argv[2]

val_dict = {}

cur = arcpy.UpdateCursor(in_table)
for row in cur:
  value = row.getValue(field)
  if value not in val_dict.keys():
    val_dict[value] = 0
  else:
    val_dict[value] += 1
    row.setValue(field, value + '_' + str(val_dict[value]))
    cur.updateRow(row)
del cur


Cheers
Arek
0 Kudos
ChrisGraves
Occasional Contributor
Great thank you Arek that has done the trick 🙂
0 Kudos