<?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 Python if then codeblock in field calculator in New to GIS Questions</title>
    <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326199#M857</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to write an if then code block for field calculator to see if the value in field A equals 0, and if it is to make the value in field B equal -1.&amp;nbsp; Else do nothing.&amp;nbsp; How can I do this?&amp;nbsp; FIeld A is type float &amp;amp; field B is type interger.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 Sep 2015 14:45:30 GMT</pubDate>
    <dc:creator>KeithAddison1</dc:creator>
    <dc:date>2015-09-14T14:45:30Z</dc:date>
    <item>
      <title>Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326199#M857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to write an if then code block for field calculator to see if the value in field A equals 0, and if it is to make the value in field B equal -1.&amp;nbsp; Else do nothing.&amp;nbsp; How can I do this?&amp;nbsp; FIeld A is type float &amp;amp; field B is type interger.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 14:45:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326199#M857</guid>
      <dc:creator>KeithAddison1</dc:creator>
      <dc:date>2015-09-14T14:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326200#M858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;They can be emulated using this syntax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;simple comparison and reclass&lt;/P&gt;&lt;P&gt;&amp;nbsp; " True condition " if !some_field! == "some_value" else " False condition "&lt;/P&gt;&lt;P&gt;ie .&amp;nbsp; "Agricultural 10 Acres" if !Zone! == "A-10" else "False"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 1&amp;nbsp; if !A! == 0 else -999&lt;/P&gt;&lt;P&gt;assuming you are calculating in the B field, using python and you can't do nothing...so I put in -999 and you can replace it with integer nothingness&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 15:04:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326200#M858</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-09-14T15:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326201#M859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming you are using ArcMap since you mentioned field calculator:&lt;BR /&gt;Right click the field you wish to change to -1 and calculate that field.&lt;/P&gt;&lt;P&gt;Switch the radio button to Python&lt;/P&gt;&lt;P&gt;In the code block enter:&lt;/P&gt;&lt;P&gt;def changefield(whatif,okthen):&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (whatif == 0):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; okthen = -1&lt;/P&gt;&lt;P&gt;&amp;nbsp; return okthen&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then in the text box below FIELDB&amp;nbsp; =&lt;/P&gt;&lt;P&gt;Enter: changefield(!FIELDA!, !FIELDB!)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 15:06:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326201#M859</guid>
      <dc:creator>RyanClose</dc:creator>
      <dc:date>2015-09-14T15:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326202#M860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Python has&lt;A href="https://docs.python.org/2/reference/expressions.html#conditional-expressions"&gt; conditional expressions&lt;/A&gt;, a.k.a., ternary operators, that can be used in situations like this one.&amp;nbsp; Using a ternary operator eliminates the need for using a code block and defining a function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14422645335614169 jive_text_macro" data-renderedposition="71_8_912_16" jivemacro_uid="_14422645335614169"&gt;&lt;P&gt;-1 if !FieldA! == 0 else !FieldB!&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:02:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326202#M860</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-09-14T21:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326203#M861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm my previous thoughts exactly&amp;nbsp; &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2015 21:21:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326203#M861</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-09-14T21:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python if then codeblock in field calculator</title>
      <link>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326204#M862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Excellent. Nice to know!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Sep 2015 15:00:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/new-to-gis-questions/python-if-then-codeblock-in-field-calculator/m-p/326204#M862</guid>
      <dc:creator>RyanClose</dc:creator>
      <dc:date>2015-09-15T15:00:01Z</dc:date>
    </item>
  </channel>
</rss>

