<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python IF/THEN within Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413194#M32522</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't had the opportunity to test this out just yet, but I do have a couple other quick questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; It shouldn't matter if field1 isn't involved in the concatenation, right?&amp;nbsp; Just so long as I add all of the fields within the parentheses in both sections?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; I also don't think it would be an issue adding characters in the return statement, right?&amp;nbsp; (e.g. field1 + "-" + field2 + "-" + field3 etc...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the information.&amp;nbsp; I'll post back whenever I have the opportunity to try this out. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Mar 2015 18:22:33 GMT</pubDate>
    <dc:creator>CoyPotts1</dc:creator>
    <dc:date>2015-03-23T18:22:33Z</dc:date>
    <item>
      <title>Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413192#M32520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a python IF/THEN statement within a model that runs the field calculator tool.&amp;nbsp; Essentially I want it to check to make sure if a cell has data entered (IS NOT NULL), and if so, calculate a concatenation of 4 other fields.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sample of what I want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF field1 &amp;lt;&amp;gt; NULL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN field2 = concatenation expression&lt;/P&gt;&lt;P&gt;ELSE field1 still = NULL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My python skills are very rudimentary, and I have only tested off of what I've found through googling python IF/THEN statements.&amp;nbsp; I don't fully understand how to take their samples and make them work with what I need to accomplish.&amp;nbsp; One of the samples that I've tried to mimic is pasted below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;Expression:&lt;BR /&gt;Reclass(!WELL_YIELD!)&lt;BR /&gt;&lt;BR /&gt;Expression Type:&lt;BR /&gt;PYTHON_9.3&lt;BR /&gt;&lt;BR /&gt;Code Block:&lt;BR /&gt;def Reclass(WellYield):&lt;BR /&gt;&amp;nbsp; if (WellYield &amp;gt;= 0 and WellYield &amp;lt;= 10):&lt;BR /&gt;&amp;nbsp; return 1&lt;BR /&gt;&amp;nbsp; elif (WellYield &amp;gt; 10 and WellYield &amp;lt;= 20):&lt;BR /&gt;&amp;nbsp; return 2&lt;BR /&gt;&amp;nbsp; elif (WellYield &amp;gt; 20 and WellYield &amp;lt;= 30):&lt;BR /&gt;&amp;nbsp; return 3&lt;BR /&gt;&amp;nbsp; elif (WellYield &amp;gt; 30):&lt;BR /&gt;&amp;nbsp; return 4&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 17:09:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413192#M32520</guid>
      <dc:creator>CoyPotts1</dc:creator>
      <dc:date>2015-03-23T17:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413193#M32521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;In Python Null is None.&amp;nbsp; Use != instead of &amp;lt;&amp;gt;.&amp;nbsp; All if clauses and else clauses must end in a colon.&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;You don't set field values in a calculation you calculate a given field and return values to it.&amp;nbsp; If and else cannot be capitalized (capitalization and spacing matter in Python).&amp;nbsp; You must include all fields used for concatentation in the parameter list passed to the def of the method.&amp;nbsp; So your sample calculation should look like this (it will assign the concatenated value or Null (None) to field2):&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;Expression:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;Reclass(!field1!, !Otherfield!)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;Expression Type:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;PYTHON_9.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;Code Block:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: monospace;"&gt;def Reclass(field1, otherfield):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field1 != None:&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return field1 + otherfield&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return None&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 17:18:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413193#M32521</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-03-23T17:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413194#M32522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't had the opportunity to test this out just yet, but I do have a couple other quick questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; It shouldn't matter if field1 isn't involved in the concatenation, right?&amp;nbsp; Just so long as I add all of the fields within the parentheses in both sections?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; I also don't think it would be an issue adding characters in the return statement, right?&amp;nbsp; (e.g. field1 + "-" + field2 + "-" + field3 etc...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the information.&amp;nbsp; I'll post back whenever I have the opportunity to try this out. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 18:22:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413194#M32522</guid>
      <dc:creator>CoyPotts1</dc:creator>
      <dc:date>2015-03-23T18:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413195#M32523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The answer to question 1 is that any field that has to be compared using the if/then logic or that has to be used to build your concatenated return value must be in the parentheses in both section.&amp;nbsp; So if you want to concatenate field1, field2 and field3 in the calculation, all 3 must be in the method parentheses.&amp;nbsp; The actual field from the field list must be used in the list in the expression portion, but any variable name that represents that field can be used in the def method in the code block.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The concatenation expression can include literal strings and field values in exactly the way you have shown.&amp;nbsp; Python considers single quotes and double quotes to be equivalent (as long as they are used in pairs to open and close the string).&amp;nbsp; So field1 + "-" + field2 + "-" + field3 and field1 + '-' + field2 + '-' + field3 work the same.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2015 18:34:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413195#M32523</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-03-23T18:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413196#M32524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: black;"&gt;As the “VB” is no longer available within the “field calculator” tool, I couldn’t figure out how to write a code for the if statement in Python for the 5 cases shown in the screenshot below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black;"&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/487505_Clip_305.jpg" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black;"&gt;&lt;IMG alt="" class="jive-emoji jive-image image-2 j-img-original" src="https://community.esri.com/legacyfs/online/487506_Clip_306.jpg" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Apr 2020 17:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413196#M32524</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2020-04-04T17:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413197#M32525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Follow the screenshot below and it will work fine with you&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/487411_python.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Apr 2020 21:14:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413197#M32525</guid>
      <dc:creator>abdullahqasrawi</dc:creator>
      <dc:date>2020-04-04T21:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python IF/THEN within Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413198#M32526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: black;"&gt;Manty thanks Abdullah for the help. It works fine with me&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black;"&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/487533_Clip_309.jpg" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Apr 2020 15:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-if-then-within-field-calculator/m-p/413198#M32526</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2020-04-05T15:59:46Z</dc:date>
    </item>
  </channel>
</rss>

