<?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: Assigning different classes using ArcGIS Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144605#M63784</link>
    <description>&lt;P&gt;Two parts are going on here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;First the &lt;STRONG&gt;in&lt;/STRONG&gt; check is going to be True every time as it is written. So regardless of the value given it should return either "High frost risk" "Low frost risk"&amp;nbsp;when using "CT" or anything else respectively. Updating, as dan mentioned, to checking if the value is in a list will solve this check.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second part is based on the elif for ST1. When it sees ST1, ST2 or ST3 it proves True and it is going to step into that block. So it will never reach the next check, which incorporates the&amp;nbsp;FIRST_FROS variable.&lt;/P&gt;&lt;P&gt;Two possible solutions.&lt;/P&gt;&lt;P&gt;1. invert the elif statements so your&amp;nbsp;FIRST_FROS check comes before the check without&amp;nbsp;FIRST_FROS.&lt;/P&gt;&lt;P&gt;2. add a nested if within the ST1... check to see if that&amp;nbsp;FIRST_FROS check is True or not.&lt;/P&gt;&lt;P&gt;Option 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(FIRST_KOPP , FIRST_FROS):
    if FIRST_KOPP in ['CT']: 
        return "High frost risk"
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3'] and FIRST_FROS in ['Moderate frost risk', 'High frost risk']:
        return "Low frost risk"
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3']:
        return "Frost free"
    elif FIRST_KOPP in ['ST4', 'ST5', 'ST6', 'ST7', 'ST8', 'ST9']:
        return "Frost free"
    elif FIRST_KOPP in ['WT'] and FIRST_FROS in ['Frost free']:
        return "Low frost risk"
    else:
        return FIRST_FROS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Option 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;def reclass(FIRST_KOPP , FIRST_FROS):
    if FIRST_KOPP in ['CT']: 
        return "High frost risk"
        
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3']:
        if FIRST_FROS in ['Moderate frost risk', 'High frost risk']:
            return "Low frost risk"
        else:
            return "Frost free"

    elif FIRST_KOPP in ['ST4', 'ST5', 'ST6', 'ST7', 'ST8', 'ST9']:
        return "Frost free"
        
    elif FIRST_KOPP in ['WT'] and FIRST_FROS in ['Frost free']:
        return "Low frost risk"
    else:
        return FIRST_FROS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Feb 2022 14:06:40 GMT</pubDate>
    <dc:creator>CodyScott</dc:creator>
    <dc:date>2022-02-16T14:06:40Z</dc:date>
    <item>
      <title>Assigning different classes using ArcGIS Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144210#M63760</link>
      <description>&lt;P&gt;below is the code with what I have come up with. I have two columns, one name First_kopp that have the classes CT, WT, ST ranging from 1-9, and the second column is named First-fros. There are conditions that have to be met based on both columns as expressed in the code below, however, thiS&lt;A href="https://www.olansise.com" target="_self"&gt;&amp;nbsp;&lt;/A&gt;Code does not seem to work:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;def&lt;/SPAN&gt; &lt;SPAN class=""&gt;reclass&lt;/SPAN&gt;(&lt;SPAN class=""&gt;FIRST_KOPP , FIRST_FROS&lt;/SPAN&gt;):
   &lt;SPAN class=""&gt;if&lt;/SPAN&gt; &lt;SPAN class=""&gt;'CT'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_KOPP: 
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;"High frost risk"&lt;/SPAN&gt;
   &lt;SPAN class=""&gt;elif&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST1'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST2'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST3'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_KOPP:
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;"Frost free"&lt;/SPAN&gt;
   &lt;SPAN class=""&gt;elif&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST1'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST2'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST3'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_KOPP &lt;SPAN class=""&gt;and&lt;/SPAN&gt; &lt;SPAN class=""&gt;'Moderate frost risk'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'High frost risk'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_FROS:
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;"Low frost risk"&lt;/SPAN&gt;
   &lt;SPAN class=""&gt;elif&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST4'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST5'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST6'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST7'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST8'&lt;/SPAN&gt; &lt;SPAN class=""&gt;or&lt;/SPAN&gt; &lt;SPAN class=""&gt;'ST9'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_KOPP:
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;"Frost free"&lt;/SPAN&gt;
   &lt;SPAN class=""&gt;elif&lt;/SPAN&gt; &lt;SPAN class=""&gt;'WT'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_KOPP &lt;SPAN class=""&gt;and&lt;/SPAN&gt; &lt;SPAN class=""&gt;'Frost free'&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; FIRST_FROS:
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;"Low frost risk"&lt;/SPAN&gt;
   &lt;SPAN class=""&gt;else&lt;/SPAN&gt;:
               &lt;SPAN class=""&gt;return&lt;/SPAN&gt; FIRST_FROS&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 12:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144210#M63760</guid>
      <dc:creator>Dastageerkhan</dc:creator>
      <dc:date>2022-02-17T12:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning different classes using ArcGIS Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144249#M63764</link>
      <description>&lt;LI-CODE lang="python"&gt;if FIRST_KOPP in ['ST1', 'ST2', 'ST3']:
  etcetera&lt;/LI-CODE&gt;&lt;P&gt;I am assuming that FIRST_KOPP comes from a field? and if you are doing this for a table, tables are processed row by row and will return 1 value at a time&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 19:33:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144249#M63764</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-02-15T19:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning different classes using ArcGIS Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144278#M63769</link>
      <description>&lt;P&gt;When you say it doesn't work do you mean it generates an error, it doesn't return a value, or it returns an unexpected value?&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I test the code, it returns a value, just not the one I expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I enter "ST1" and "Moderate frost risk" into the function and get "Frost free" when I would expect to get "Low frost risk".&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this is elif is exiting the function when it find the first match for 'ST1' in FIRST_KOPP (I.E. the first elif in the function) so it never makes it second elif&amp;nbsp;to return 'Low frost risk".&amp;nbsp; Is this the behavior you are referring&amp;nbsp; to?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Feb 2022 20:28:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144278#M63769</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-02-15T20:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning different classes using ArcGIS Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144605#M63784</link>
      <description>&lt;P&gt;Two parts are going on here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;First the &lt;STRONG&gt;in&lt;/STRONG&gt; check is going to be True every time as it is written. So regardless of the value given it should return either "High frost risk" "Low frost risk"&amp;nbsp;when using "CT" or anything else respectively. Updating, as dan mentioned, to checking if the value is in a list will solve this check.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second part is based on the elif for ST1. When it sees ST1, ST2 or ST3 it proves True and it is going to step into that block. So it will never reach the next check, which incorporates the&amp;nbsp;FIRST_FROS variable.&lt;/P&gt;&lt;P&gt;Two possible solutions.&lt;/P&gt;&lt;P&gt;1. invert the elif statements so your&amp;nbsp;FIRST_FROS check comes before the check without&amp;nbsp;FIRST_FROS.&lt;/P&gt;&lt;P&gt;2. add a nested if within the ST1... check to see if that&amp;nbsp;FIRST_FROS check is True or not.&lt;/P&gt;&lt;P&gt;Option 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(FIRST_KOPP , FIRST_FROS):
    if FIRST_KOPP in ['CT']: 
        return "High frost risk"
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3'] and FIRST_FROS in ['Moderate frost risk', 'High frost risk']:
        return "Low frost risk"
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3']:
        return "Frost free"
    elif FIRST_KOPP in ['ST4', 'ST5', 'ST6', 'ST7', 'ST8', 'ST9']:
        return "Frost free"
    elif FIRST_KOPP in ['WT'] and FIRST_FROS in ['Frost free']:
        return "Low frost risk"
    else:
        return FIRST_FROS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Option 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;def reclass(FIRST_KOPP , FIRST_FROS):
    if FIRST_KOPP in ['CT']: 
        return "High frost risk"
        
    elif FIRST_KOPP in ['ST1', 'ST2', 'ST3']:
        if FIRST_FROS in ['Moderate frost risk', 'High frost risk']:
            return "Low frost risk"
        else:
            return "Frost free"

    elif FIRST_KOPP in ['ST4', 'ST5', 'ST6', 'ST7', 'ST8', 'ST9']:
        return "Frost free"
        
    elif FIRST_KOPP in ['WT'] and FIRST_FROS in ['Frost free']:
        return "Low frost risk"
    else:
        return FIRST_FROS&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Feb 2022 14:06:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assigning-different-classes-using-arcgis-field/m-p/1144605#M63784</guid>
      <dc:creator>CodyScott</dc:creator>
      <dc:date>2022-02-16T14:06:40Z</dc:date>
    </item>
  </channel>
</rss>

