<?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: Field Calculator Python IF statement in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1591514#M93620</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/380056"&gt;@MarcoOrlandi1&lt;/a&gt;&amp;nbsp;Peaced what you had into this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(
    in_table="Your_table",
    field="Historic_period",
    expression="calc_historic_period(!Century!)",
    expression_type="PYTHON3",
    code_block="""def calc_historic_period(century):
    if century == 6:
        return "late antiquity"
    elif century == 10:
        return "Middle age"
    else:
        return "Other" """,
    field_type="TEXT"
)&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 04 Mar 2025 01:37:13 GMT</pubDate>
    <dc:creator>JonathanNeal</dc:creator>
    <dc:date>2025-03-04T01:37:13Z</dc:date>
    <item>
      <title>Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297123#M12898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I’m trying to use IF statements in field calculator to fill a field starting from another field’s values:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field to fill up: &lt;STRONG&gt;Historic_period&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Field already filled:&amp;nbsp;&lt;STRONG&gt;Century&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Statement in human language:&lt;/P&gt;&lt;P&gt;IF Century = 6 then write “late antiquity”, IF Century=10 the write “Middle age” etc etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I’m struggling trying to set up the correct syntax in ArcGis Pro Filed Calculator but I’m always missing something…..&lt;/P&gt;&lt;P&gt;Can someone help and guide me step by step (I don't know how to use the helpers and the Code Block....)?&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 May 2017 22:18:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297123#M12898</guid>
      <dc:creator>MarcoOrlandi1</dc:creator>
      <dc:date>2017-05-28T22:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297124#M12899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;without getting into specifics for your case... examine this image and return with questions.&amp;nbsp; In ArcMap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/354332_field_calc03.png" style="width: 326px; height: 451px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And so you can see the similarities and difference in PRO&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/354333_Field_calc_pro_01.png" style="width: 415px; height: 855px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 May 2017 22:42:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297124#M12899</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-05-28T22:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297125#M12900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the comparison, very helpful!&lt;/P&gt;&lt;P&gt;Do you know how&amp;nbsp;to format for a string input as the condition to hunt for when calculating the field?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ex. (Build_Code is the field to calculate, Build_Type is the conditional field)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Build_Code =&lt;BR /&gt;Type(!Build_Type!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Type(fld):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if fld == "Neighborhood"&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value = 1&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif fld == "Apartment"&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value = 2&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elif fld == "Condo" &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value = 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return value&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Oct 2018 04:15:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297125#M12900</guid>
      <dc:creator>KatR_</dc:creator>
      <dc:date>2018-10-18T04:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297126#M12901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kat, you are missing : 's at the end of your if lines&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;Type&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld&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; fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Neighborhood"&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; value &lt;SPAN class="operator token"&gt;=&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; fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Apartment"&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; value &lt;SPAN class="operator token"&gt;=&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;elif&lt;/SPAN&gt; fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Condo"&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; value &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; value&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The field you are calculating values for should be of type 'short' or 'long'&lt;/P&gt;&lt;P&gt;and the 'expression' for that field would be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Type(!Build_Type!)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;where the !Build_Type! is the field containing the text classes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/297126#M12901</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1105783#M46458</link>
      <description>&lt;P&gt;Hello, this is an excellent post. In PRO I am trying to do essentially the same thing as KatR, except need to replace !prim_lith! (a text field with geologic material descriptions, eg, clay) with a new !prim_lith_reclass! (a short integer field) whose value depends on the geologic material.&amp;nbsp; The Expression is valid but the return values are all equal to 1 (should be 1-9). I've tried varied syntax etc. but nothing seems to work.&amp;nbsp; Any insights would be greatly appreciated!&amp;nbsp; Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Oct 2021 03:36:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1105783#M46458</guid>
      <dc:creator>GJB</dc:creator>
      <dc:date>2021-10-08T03:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1106230#M46530</link>
      <description>&lt;P&gt;If statements are executed in order, so looking at your first statement:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if fld != "Soil or Fill:&lt;/LI-CODE&gt;&lt;P&gt;Every record but those with "Soil or Fill" will return True, which means they all will get mapped to the value 1.&amp;nbsp; Records with "Soil or Fill" will be caught by the second statement&lt;/P&gt;&lt;LI-CODE lang="python"&gt;elif fld != "Alluvium":&lt;/LI-CODE&gt;&lt;P&gt;and get mapped to the value 2.&lt;/P&gt;&lt;P&gt;In short, given your existing if statement structure, records can only have a value of 1 or 2 with most of them all being 1.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1106230#M46530</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-10-09T16:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1276825#M67761</link>
      <description>&lt;P&gt;In my opinion, calculated columns should be easier in ArcGIS Pro:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/virtual-attributes-ad-hoc/idc-p/1276472#M24314" target="_self"&gt;Virtual Attributes (ad hoc)&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;I want to be able use SQL like this:&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier" color="#999999"&gt;case when a&amp;lt;&amp;gt;b then 1 end&lt;/FONT&gt;&amp;nbsp; .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To me, that would be better than creating a new field in the FC and fumbling with the field calculator. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This post has ~42,000 hits. And there are ten other posts like it. That suggests to me that field calculator IF statements need improving.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 19:51:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1276825#M67761</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-04-09T19:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1591513#M93619</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/351335"&gt;@Bud&lt;/a&gt;&amp;nbsp;The where clause is supported in the calculate field&lt;STRONG&gt;s&lt;/STRONG&gt; tool.&amp;nbsp; If you are just doing one calculation, use Select Layer By Attributes then calculate.&lt;BR /&gt;&lt;BR /&gt;Tool Doc:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-fields.htm" target="_blank"&gt;Calculate Fields (multiple) (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 01:34:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1591513#M93619</guid>
      <dc:creator>JonathanNeal</dc:creator>
      <dc:date>2025-03-04T01:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python IF statement</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1591514#M93620</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/380056"&gt;@MarcoOrlandi1&lt;/a&gt;&amp;nbsp;Peaced what you had into this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(
    in_table="Your_table",
    field="Historic_period",
    expression="calc_historic_period(!Century!)",
    expression_type="PYTHON3",
    code_block="""def calc_historic_period(century):
    if century == 6:
        return "late antiquity"
    elif century == 10:
        return "Middle age"
    else:
        return "Other" """,
    field_type="TEXT"
)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 04 Mar 2025 01:37:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/field-calculator-python-if-statement/m-p/1591514#M93620</guid>
      <dc:creator>JonathanNeal</dc:creator>
      <dc:date>2025-03-04T01:37:13Z</dc:date>
    </item>
  </channel>
</rss>

