Unless I'm missing the point, calling the Summary Statistics tool will do this in one line of code?arcpy.Statistics_analysis("Export_Output","in_memory/x",[["ID","COUNT"]],"ID")This creates a table called X in the in_memory workspace and returns a count on a field called ID.
arcpy.Statistics_analysis("Export_Output","in_memory/x",[["ID","COUNT"]],"ID")
count_duplicates("I/live_data.dbf",'id')
from collections import Counter def count_duplicates(path_to_data, field_to_count): #Add the count field data_layer = arcpy.MakeFeatureLayer_management(path_to_data, 'data') arcpy.AddField_management(data_layer, 'COUNT', 'LONG') arcpy.Delete_management(data_layer) del data_layer #Do the counting: value_list = [] with arcpy.da.SearchCursor(path_to_data, [field_to_count]) as search_rows: for row in search_rows: value_list.append(row[0]) counts = Counter(value_list) del value_list with arcpy.da.UpdateCursor(path_to_data, [field_to_count, 'COUNT']) as update_rows: for row in udpate_rows: row[1] = counts[row[0]] update_rows.updateRow(row)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.