Use Python to Find duplicate values in a feature Class and populate a field
Something like this should work:
import arcpy
inShapefile = pointsShapefile
checkField = "xyCombine"
updateField = "dplicate"
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'
else:
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]]
rows.updateRow(row)
And as @mr.adam suggested, the dictionary is not needed. here is the cleaner version:
import arcpy
def findDupes(inShapefile, checkField, updateField):
with arcpy.da.SearchCursor(inShapefile, [checkField]) as rows:
values = [r[0] for r in rows]
with arcpy.da.UpdateCursor(inShapefile, [checkField, updateField]) as rows:
for row in rows:
if values.count(row[0]) > 1:
row[1] = 'Y'
else:
row[1] = 'N'
rows.updateRow(row)
if __name__ == '__main__':
fc = r'C:\TEMP\crm_test.gdb\test'
fld = 'Project_Manager'
up = 'duplicates'
findDupes(fc, fld, up)
If you have an Advanced or Info license, another option in Arc is to use the Find Identical tool. This will give you a table of ID rows with matching values. Use the ONLY_DUPLICATES option. Then join the table to the feature class (fc ObjectID to InFID of table), using the KEEP_COMMON keyword for the join type (this is similar to a definition query, in that your feature class will only display matching records).. Then perform a field calculation on the layer. Finally, remove the join so the rest of the features are available.
I don't know how this compares with the da cursor for efficiency. Just another option.