I am working with .dbf files. I have two columns of data that have duplicates. A column of parcel numbers with duplicates and a column of letters that are duplicated. I want to delete all parcel numbers first and then delete all duplicate letter numbers after. Right now, I'm just repeating code twice.
Is there an easier way?
I'm brand new at this so that's why the code is repeated and looks so chunky. It's code that I mostly found off this site previously.
Here's what I'm working with:
import arcpy
import os
from arcpy import env
inShapefile = "M:/GIS/LEA Maps/2019/List/GISLEA.dbf"
checkField = 'PARCELNO'
updateField = 'dplicate'
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'M:/GM/LEA/LEADR.dbf'
findDupes(fc, checkField, updateField)
arcpy.DeleteIdentical_management(fc, 'PARCELNO')
inShapefile = 'M:/GM/LEA/LEADR.dbf'
checkField = 'LetterOrde'
updateField = 'dplicate'
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 = 'M:/GM/LEA/LEADRlo.dbf'
findDupes(fc, checkField, updateField)
arcpy.DeleteIdentical_management(fc, 'LetterOrde')