AnsweredAssumed Answered

Find Duplicates records

Question asked by CCweedcontrol on May 9, 2017
Latest reply on May 12, 2017 by rvburton

 I need to be able to add increments to duplicates in the P_ID field like below with arcpy. No sure how to though.


P_ID 23560 -->0

P_ID 23560 -->1

P_ID 23560 -->2

P_ID 23560 -->3

P_ID 23560 -->4

P_ID 23571 -->0

P_ID 23571 -->1

P_ID 23571 -->2.


 I am working with the following code that adds 'Y' or 'No'  in search of duplicates. Duplicates get a 'Y' and none Duplicates get 'N'.


import arcpy

#find Duplicate records, add Y or N in updateFeild

inShapefile = 'VacantLots'
checkField = "P_ID"
updateField = "Count"

with arcpy.da.SearchCursor(inShapefile, [checkField]) as rows:
    values = [r[0] for r in rows]

d = {}
for item in set(values):
    if values.count(item) > 1:
        d[item] = 'Y'
        d[item] = 'N'

with arcpy.da.UpdateCursor(inShapefile, [checkField, updateField]) as rows:
    for row in rows:
        if row[0] in d:
            row[1] = d[row[0]]