<?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: If statement in Python in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271377#M15661</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;post your code since your indentation is not correct in the if block since 4 spaces per indentation level.&amp;nbsp; If you have many to reclass, then an if else approach is not the one to take.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 May 2017 18:31:02 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-05-09T18:31:02Z</dc:date>
    <item>
      <title>If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271374#M15658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have two attributes for counties and districts. I need to write a script in Python to get the District IDs based on the counties. I am not a developer so I may have mistakes in my script attached. I appreciate your help.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 17:36:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271374#M15658</guid>
      <dc:creator>AzaN</dc:creator>
      <dc:date>2017-05-09T17:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271375#M15659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Notice the syntax in the following example&lt;/P&gt;&lt;P&gt;you have to have a function (ie def reclass) which you pass parameters to (ie a), but in the expression box, you will notice that you pass a field name enclosed in double quotes to the function (ie reclass(!Id!) in the example.&lt;/P&gt;&lt;P&gt;Now the function is specific about indentation.&amp;nbsp; 4 spaces is standard, with the def line unindented.&amp;nbsp; The if statement in my example does an equality check notice the colon at the end.&amp;nbsp; If the equality is met, then the variable 'a' is assigned 1,&amp;nbsp; it is indented 4 spaced.&amp;nbsp; The 'else' section is where program focus moves it a doesn't equal 1, whereby a is assigned 0.&amp;nbsp; Finally a value is returned.&amp;nbsp; Now you can proceed to fix your code.&amp;nbsp; In future, it would be better to copy and paste the snippet, so that people can edit your exact example without having to refer back to an image.&lt;/P&gt;&lt;P&gt;Good luck&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/350325_field_calc03.png" style="width: 373px; height: 516px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 17:44:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271375#M15659</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-05-09T17:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271376#M15660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks or your response. I followed all your instructions (please see the image attached). But it does not work. By the way, there are 33 counties, but I am just trying the code for two counties for now. Also, the County field&amp;nbsp;is a string attribute and District is short integer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 18:22:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271376#M15660</guid>
      <dc:creator>AzaN</dc:creator>
      <dc:date>2017-05-09T18:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271377#M15661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;post your code since your indentation is not correct in the if block since 4 spaces per indentation level.&amp;nbsp; If you have many to reclass, then an if else approach is not the one to take.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 18:31:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271377#M15661</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-05-09T18:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271378#M15662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;def reclass(a):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a == 'Wicomico':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;BR /&gt;&amp;nbsp;elif a == 'Cecil':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else: &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 18:41:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271378#M15662</guid>
      <dc:creator>AzaN</dc:creator>
      <dc:date>2017-05-09T18:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271379#M15663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to classify 33 counties (for 287 camera records) into 7 districts. If I don't use if statement, what else can I use? Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 18:44:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271379#M15663</guid>
      <dc:creator>AzaN</dc:creator>
      <dc:date>2017-05-09T18:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271380#M15664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you say it isn't working, what do you mean, exactly?&amp;nbsp; Is it generating an error?&amp;nbsp; If so, post the error.&amp;nbsp; Is it giving unexpected results?&amp;nbsp; What are those results and how do they differ from what you expect?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, what you just posted here doesn't line up exactly with your screenshot.&amp;nbsp; The screenshot appears to show an extra gap between the 2 equals signs for the second comparison.&amp;nbsp; Also, your indentation above is all off, this is how it should look when/if using 4 spaces:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;reclass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; a &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Wicomico'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; a &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Cecil'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:16:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271380#M15664</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T13:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271381#M15665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;a nested if statement with 33 comparisons is not the route to go.&amp;nbsp; producing a separate table for join/relates to do the conversion is what I was referring to.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 May 2017 22:52:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271381#M15665</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-05-09T22:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271382#M15666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 May 2017 17:18:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271382#M15666</guid>
      <dc:creator>AzaN</dc:creator>
      <dc:date>2017-05-10T17:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: If statement in Python</title>
      <link>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271383#M15667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your If statement do return you do not need to use elif&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;P&gt;if a == 'Wicmico': return 1&lt;/P&gt;&lt;P&gt;if a == 'Cecil': return 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it does not look so wrong.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 May 2017 05:01:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/if-statement-in-python/m-p/271383#M15667</guid>
      <dc:creator>ModyBuchbinder</dc:creator>
      <dc:date>2017-05-11T05:01:58Z</dc:date>
    </item>
  </channel>
</rss>

