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?
It returns no value. It returns a error 000989: Python syntax error.
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?
!NADR_ID! if !NADR_ID! in !ABOVE! else None
try the 'in' operator
Thanks! But there is one problem. Reason, why I tried to use SearchCursor is that I have more than one number in second culomn.
Why do you need a search cursor? you can use the field calculator for that
python parser
!NADR_ID! if !NADR_ID! == !ABOVE! else None
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:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">myfunc</SPAN><SPAN class="punctuation token">(</SPAN>field1<SPAN class="punctuation token">,</SPAN> field2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> str<SPAN class="punctuation token">(</SPAN>field1<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">in</SPAN> field2<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> field1 <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> None<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Then in the box above the codeblock, put the following line
my_func<SPAN class="punctuation token">(</SPAN>!NADR_GID!<SPAN class="punctuation token">,</SPAN> !ABOVE!<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
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!
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.