1

I have 2 tables. Each table has an ID and i need to insert only one attribute from first table to a specific field in the second table using python script. This should be done using UpdateCursor, but i can't figure out how, Any tips?

3

Many options.

First, you can use Join Field from Data Management

Second, you can create a new field, join the second table with Add Join from Data Management and then calculate your newly created field with simple excpression [table1.TARGETFIELD] = [table2.JOINEDFIELD]

Third, you can read everything to python dicitionary {id: value} with SearchCursor:

joined_data = {row[0]: row[1] for row in arcpy.da.SearchCursor(table2, ['ID', 'JOINEDFIELD']}

and than update your first table with UpdateCursor:

default_value = _write_your_default_value_here_
with arcpy.da.UpdateCursor(table1, ['ID', 'TARGETFIELD']) as uc:
    for row in uc:
        row[1] = joined_data.get(row[0], default_value)
        uc.updateRow(row)

Don't forget to build attribute indexes if you'd use first two options.

Actually, it's almost the same situation as described in this question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.