Hello, this is my first time posting a question so sorry if my question sounds confusing!
I am trying to create a way to get the first unique value from my input table, find its duplicates based on its ID field, and only return the row with the latest date and output it to a new table. Then I need this process to repeat for each unique value in the input table and output all the results to the same table.
Ex Input Table:
ID | Activity | StopDate |
1 | a | 01/2020 |
1 | b | 07/2018 |
2 | c | 04/2008 |
2 | d | 09/2021 |
2 | e | 03/2014 |
7 | f | 10/2022 |
9 | g | 06/2017 |
9 | h | 12/2023 |
Ex Output Table:
ID | Activity | StopDate |
1 | a | 01/2020 |
2 | d | 09/2021 |
7 | f | 10/2022 |
9 | h | 12/2023 |
The model I made to try and do this does not work because I am probably not using the right tools or using them in the right order...
And here's a code snippet I tried to use from another similar post and I just changed the variables to match my data, but it did not work either.
import arcpy
fc = "COGPWorks_ExportFeatures"
rig_number = 'CarteID'
date_field_sort = 'StopDateActual'
update_cursor = arcpy.UpdateCursor(fc, '', '', 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 know how to make buffers do simple calculations but when attempting multiple tools that are dependent on each other, I get confused. I am fairly new to model builder and have little experience with coding so I do not know where to start, so any guidance will be helpful!