I am trying to use an update cursor on a shapefile to calculate a row from a dictionary and must be missing something very simple. below is my code
so my dictionary is called adict
adict = {'source': {0: u'SUN', 1: u'DAN'}, u'WORK_TYPE': {0: u'FRA', 1: u'UKB'}, u'API_NUM': {0: '422973', 1: '422873'}
And i am trying to calculate worktype in my shapefile.
with arcpy.da.UpdateCursor(myshapefile, ['API_NUM','WORK_TYPE']) as cursor:
for row in cursor:
if row[0] in adict['API_NUM'].values():
row[1]=adict[row[0]]
cursor.updateRow(row)
else:
print 'no'
i'm trying to set the row value on the shapefile to the corresponding dictionary value.
I am trying to calculate my work_type column in the shapefile with the work_type value from the dictionary based on the matching API_NUM
, so for api = 422873
, the worktype would be UKB
.
If i were using geopandas, i would convert the dict to a dataframe and merge on api. Using arcpy right now i am iterating through both sets of data and calculating the work value from the corresponding dict data, but because there are so many records in both sets, it's taking a while using that method. so i thought a dictionary may be faster. I know i could convert to array, then to a table, but that just seems like a bunch of steps.