I'm trying to use the Field Calculator (python) to replace existing values (string) in Field1 with the values in Field2 (string) but only if Field2 is not Null.
Having trouble with the syntax.
Thanks,
John
John,
In Field Calculator you will want to create a def statement in the code block and pass the values of Field1 and Field2 to this statement. The Statement will look something like the following:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">checkValue</SPAN><SPAN class="punctuation token">(</SPAN>f1<SPAN class="punctuation token">,</SPAN> f2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> f2 <SPAN class="keyword token">is</SPAN> None<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> f1 <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">return</SPAN> f2 <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You would call the function using:
checkValue(!field1!, !field2!)
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.