1

I'm going to be as descriptive as possible. I have a table (TA) with values which are null for some rows, filled out for others. I have a table (TB) with the null values filled out.

Dec in TA is the shared value in TB (called Nulled in that table)

I can't do a table join because this would duplicate the amount of nulled columns in the first table. The gist of what I want it to do is this: if CURR_TYPE (one of the columns) is null in TA, lookup its Dec value, go to TB, look for the same value under Nulled, copy TB's CURR_TYPE, and paste it onto TA's CURR_TYPE.

This is what I have so far, and I've tried variations on things I've found here, but I get lost with how to tell python to LOOKUP in another field, copy and

# Import arcpy module
import arcpy
# Local variables:
TA = "F:...\\TA"
TB = "F:...\\TB"
TLDisNull = arcpy.AddFieldDelimiters(TA, "SponsorOrganization") + " IS NULL"
#Update rows
with arcpy.da.UpdateCursor(TA, "CURR_TYPE", TLDisNull) as u_cursor:
 with arcpy.da.SearchCursor(TA, "Dec") as s_cursor1:
 for s_row in s_cursor1:
 with arcpy.da.SearchCursor(TB, "Nulled") as s_cursor2:
 for s_row in s_cursor2
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 1, 2014 at 20:11

2 Answers 2

1

I think a Join would actually serve you best. Instead of using a search cursor, join the two tables together with a common field (say ID) and use the field calculator with an if statement. So in TA (the one you want to update and check for NULL values) select the field you want to update ( CURR_TYPE).

Then in the field you want to update use Field Calculator:

if [CURR_TYPE] IS NULL then
 result = [CURR_TYPETB]
#If CURR_TYPE in TA is NULL then the field = CURR_TYPE IN TB
else
 result = [CURR_TYPE]
end if

After this is completed, remove the join

answered Jun 2, 2014 at 14:58
0

Table join does not seem to be a problem in your case. You don't have to duplicate columns, you just need to calculate field to update the first table with the values of the second table, then you can remove your join.

but if you want to use cursor, here is a hint (however, this only work if the rows are in the same order and with the same number, this is why I recommend table join)

sc_tab = arcpy.da.SearchCursor(input, fields)
uc_pols = arcpy.da.UpdateCursor(table_with_null, fields )
for pol in uc_pols:
 tb = sc_tab.next()
 pol = tb 
 uc_pols.updateRow(pol)
answered Jun 1, 2014 at 20:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.