import arcpy rig_number = 'RIG_FIELD' date_field_sort = 'DATEFIELD D' update_cursor = arcpy.UpdateCursor(rigsFC, '', '', rig_number, date_field_sort) keep_list = list() for row in update_cursor: row_val = row.getValue(rig_number) if row_val not in keep_list: keep_list.append(row_val) elif row_val in keep_list: update_cursor.deleteRow(row) else: pass
I would use an update cursor, sort by date (newest to oldest) use a list to track all rig_number values, and if the value is already in the list delete that row, if it is not in the list add it and move on.
You'd want to do something closer to this. Utilizing an update cursor and the deleteRow method of the cursor, not the DeleteRows tool. import arcpy rig_number = 'RIG_FIELD' date_field_sort = 'DATEFIELD D' update_cursor = arcpy.UpdateCursor(rigsFC, '', '', rig_number, date_field_sort) keep_list = list() for row in update_cursor: row_val = row.getValue(rig_number) if row_val not in keep_list: keep_list.append(row_val) elif row_val in keep_list: update_cursor.deleteRow(row) else: pass
This did the trick! Thanks for your help!I am still confused as the difference between a search cursor and an update cursor. Is it that the update cursor is editable and thus methods such as deleteRow can be used with it? Thanks again!
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.