I try to find a match of numbers in the first column and second column, if it finds the same number in second column, it writes the value of the first column into third column. Do you have any ideas?
Hi Kristyna,
I've done something quite similar to this in the past! In this case you don't actually need to use cursors, just the field calculator using Python will do! If you right click on the third field (BELOW) and go to "calculate field", select "python" for the expression type, put the following code in the code block:
def myfunc(field1, field2):
if str(field1) in field2:
return field1
else:
return None
Then in the box above the codeblock, put the following line
my_func(!NADR_GID!, !ABOVE!)
It should do exactly what you're hoping for it to do. Basically taking the first number, converting it to a string, looking for that sequence in the second field, then returning the first field's value if there is a match!
Thanks! But there is one problem. Reason, why I tried to use SearchCursor is that I have more than one number in second culomn.
!NADR_ID! if !NADR_ID! in !ABOVE! else None
try the 'in' operator
This shouldn't be an issue from my understanding, the multiple numbers in the second column are all just strings joined by ";"s, so if the number from the first column is anywhere in the second column it will return it. Have you tried running it? If so maybe you can show me where it has returned a value that you didn't want?
It returns no value. It returns a error 000989: Python syntax error.
So in the original code I sent through, leave the field1 and field2 as they are (don't replace with your fields)! When you run myfunct(!NADR_GID!, !ABOVE!) that's substituting those values in there.
Unfortunately, it returns still same error.
Can you post another picture of what you ran this time?