0

I have a feature class that list names by travel. The issue is that they are listed by travel day which is too much repeated records.I want to keep the records in the feature class that are unique by as defined by three fields. I've been using the following codes and while it seems that the feature classes were updated (by looking at dates) but nothing seems to be changed. Is there something that I am missing? I just simply want to get rid of the duplicate records in the three fields (all in relation, not individually).

unique_list1 = set(row[0] for row in arcpy.da.SearchCursor(fc, ['field1','field2','field3']))

and

def unique_values(table, field):  
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({(row[0] for row in cursor})
2
  • If you use a set in the unique_values function, it will actually return unique values.
    – Vince
    Commented Apr 5, 2023 at 0:00
  • You cant modify features with da.SearchCursor, you need to use da.UpdateCursor (if modifying is what you are trying to do)
    – Bera
    Commented Apr 5, 2023 at 5:12

1 Answer 1

2

Why write any code at all there is a tool that can do this, Delete identical. I would suggest you work from a copy until you are confident in its output as in deletes in situ and there is no undo for it.

3
  • Delete Identical is likely way more expensive than a DA cursor, and Summary Stats is probably faster than both, though the record count and percent distinct would make a big difference.
    – Vince
    Commented Apr 5, 2023 at 0:03
  • @Hornbydd I know about it but I do not have that extension licensed.
    – BoniPhila
    Commented Apr 5, 2023 at 14:09
  • @BoniPhila you have learnt a valuable lesson, when you post a question you need to say what your license level is, stops people wasting their time trying to solve your problem with methods unavailable to you.
    – Hornbydd
    Commented Apr 5, 2023 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.