I have a point feature class.
In this screenshot you will see that ADDR_KEY contains duplicate values. I want to move the values in CROSS_ST_NAMES field to CS1StreetName field and CS2StreetName field as follows:
ADDR_KEY = 3460 (1st occurrence) then move CROSS_ST_NAMES to CS1StreetName
[the value that would be placed in CS1StreetName field would be GABLE DR/MCDUFF AVE]
then ADDR_KEY = 3460 (2nd occurrence) then move CROSS_ST_NAMES to CS2StreetName
[the value that would be placed in CS2StreetName field would be FUSTERIA CT/MCDUFF AVE]
and so on for the other ADDR_KEY values...
any ideas how to do this in python or with a geoprocessing tool? I am new to python.
Solved! Go to Solution.
I would make 2 passes through the table. First with a search cursor to find and record the duplicates, second with an update cursor to update the two fields as needed. Something like this......
addrkey_to_streets = dict()
with arcpy.da.SearchCursor(table, ['ADDR_KEY', 'CROSS_ST_NAMES']) as cursor:
for addrkey, street in cursor:
if addrkey not in addrkey_to_streets.keys():
addrkey_to_streets[addrkey] = {'first': street, 'second': None}
else:
addrkey_to_streets[addrkey]['second'] = street
with arcpy.da.UpdateCursor(table, ['ADDR_KEY', 'CS1StreetName', 'CS2StreetName']) as cursor:
for addrkey, cs1_street, cs2_street in cursor:
cursor.updateRow([addrkey, addrkey_to_streets[addrkey]['first'], addrkey_to_streets[addrkey]['second']])
I would make 2 passes through the table. First with a search cursor to find and record the duplicates, second with an update cursor to update the two fields as needed. Something like this......
addrkey_to_streets = dict()
with arcpy.da.SearchCursor(table, ['ADDR_KEY', 'CROSS_ST_NAMES']) as cursor:
for addrkey, street in cursor:
if addrkey not in addrkey_to_streets.keys():
addrkey_to_streets[addrkey] = {'first': street, 'second': None}
else:
addrkey_to_streets[addrkey]['second'] = street
with arcpy.da.UpdateCursor(table, ['ADDR_KEY', 'CS1StreetName', 'CS2StreetName']) as cursor:
for addrkey, cs1_street, cs2_street in cursor:
cursor.updateRow([addrkey, addrkey_to_streets[addrkey]['first'], addrkey_to_streets[addrkey]['second']])