AnsweredAssumed Answered

Using Search Cursor Dictionary/Update Cursor to Populate Many Fields Using Values from Another Table

Question asked by gardta on Jan 30, 2018
Latest reply on Feb 1, 2018 by gardta

I am trying to populate many new fields in a new table using values from fields in another table. I am hoping to use a combination of a da.search cursor dictionary and a da.update cursor to speed up this field update.

 

I am not receiving any errors with this code, though the field values are not populating, and the fields remain blank after that script has completed. Any suggestions on what I might need to fix?

 

"KEY_FIELD" is the unique identifier and is populated in both tables. 

 

search_feats = {f[0]:f[1] for f in arcpy.da.SearchCursor(Table_1,["key_field","field_2","field_3", "field_4", "field_5", "field_6"])}

with arcpy.da.UpdateCursor(Table_2,["KEY_FIELD","FIELD_2","FIELD_3", "FIELD_4", "FIELD_5","FIELD_6"]) as upd_cur:
     for upd_row in upd_cur:
         CodeID = upd_row[0]
         if CodeID in search_feats:
            upd_row[1] = search_feats[CodeID][0] #FIELD_2
            upd_row[2] = search_feats[CodeID][1] #FIELD_3
            upd_row[3] = search_feats[CodeID][2] #FIELD_4
            upd_row[4] = search_feats[CodeID][3] #FIELD_5
            upd_row[5] = search_feats[CodeID][4] #FIELD_6

            upd_cur.updateRow(upd_row) 

del upd_cur

Outcomes