I have a table with parcel numbers in one field and soil types in another. There are several soil types for each parcel, and therefore several records for each parcel.
I am looking for a script (Python, SQL, VB, Arcade) that will iterate through each record grouped by APN, selecting (or outputting) the LAST record for each APN.
Example input table:
APN | SOIL TYPE |
---|---|
1 | A |
2 | A |
2 | A, B |
3 | A |
3 | A, E |
3 | A, E, G |
Desired result:
APN | SOIL TYPE |
---|---|
1 | A |
2 | A, B |
3 | A, E, G |
It's a simple task that seems like it should be easy, but I can't seem to find a solution. I've been working in Excel, ModelBuilder inside of ArcGIS Pro, and Python in Jupyter Notebook, but I'm not very well versed in any one program or language; maybe there's a better route of attack.
Thank you for any suggestions you might be able to provide!
Okay, cool. Dictionaries are still a bit of a mystery to me, so I'm glad I'm on the right track: it goes back to what Joshua suggested yesterday as to what constitutes the desired outcome......
Hi Joe Borgione , to explain a little more of what is happening with the dictionary in the process, see the snippet below:
table = [[1, "A"], [2, "A"], [2, "A, B"], [3, "A"], [3, "A, E"], [3, "A, E, G"]]
dct = {}
cnt = 0
for row in table:
cnt += 1
apn = row[0]
soil_type = row[1]
dct[apn] = soil_type
print("cnt:{}\tapn:{}\tsoil_type:{}\tdct:{}".format(cnt, apn, soil_type, dct))
This will print the dictionary for each row that is being read:
cnt:1 apn:1 soil_type:A dct:{1: 'A'}
cnt:2 apn:2 soil_type:A dct:{1: 'A', 2: 'A'}
cnt:3 apn:2 soil_type:A, B dct:{1: 'A', 2: 'A, B'}
cnt:4 apn:3 soil_type:A dct:{1: 'A', 2: 'A, B', 3: 'A'}
cnt:5 apn:3 soil_type:A, E dct:{1: 'A', 2: 'A, B', 3: 'A, E'}
cnt:6 apn:3 soil_type:A, E, G dct:{1: 'A', 2: 'A, B', 3: 'A, E, G'}
So, when it finds the same apn key, the value that was stored in the dictionary for that apn key will be replaced by the last value (soil type).
Perhaps way more than needed for the question... but patterns and sequences and their analysis are useful.
Tool url will appear after ArcGIS PRO Beta 2.2 is complete.
Light reading in the interim