<?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: Trying to reclassify a field in attribute table with Python in Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393304#M31153</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander is correct, you never call a function with 'def' attached.&amp;nbsp; It is also a good idea to check your syntax and issues by running a script outside of arcmap in an python IDE.&amp;nbsp; Substitute possible values in your test def using the fieldname as the incrementer remembering to add ! before and after in the field calculator.&amp;nbsp; Now here is your example...but you will see that it will soon become ridiculous in length if there are many cases in your CAUSE's and you would be advised to examine other data structures to facilitate logic and access to reclassification (for example dictionaries etc etc).&amp;nbsp; BUT that is not the issue here... Just make sure that you don't get Lost in your CAUSE syntax &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def fld_reclass (case):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if case == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 7
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif case == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif case == 4:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
possible = [-1,0,1,2,3,4,5]
for CAUSE in possible:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # if it helps, use your fieldname as the incrementer
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = fld_reclass(CAUSE)&amp;nbsp; # now don't forget the !_before&amp;amp;after_!
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("case {}&amp;nbsp; result {}".format(CAUSE,result))
# &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:01:49 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2021-12-11T18:01:49Z</dc:date>
    <item>
      <title>Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393297#M31146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm still relatively new to Python and it's my first time implementing it in the Field Calculator. What I am trying to accomplish is the reclassification of one field "CAUSE" into a new blank field named "CAUSE_RGR". I was given a script that I would have to adapt to this current project.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I need to reclassify the numbers in the "CAUSE" column to be new numbers in the "CAUSE_RGR" as so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 --&amp;gt; 7&lt;/P&gt;&lt;P&gt;3 --&amp;gt; 2&lt;/P&gt;&lt;P&gt;4 --&amp;gt; 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was given a script that I would have to adapt to this current project, so I watched a tutorial on using python in the field calculator and came up with this script in the field calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Pre-Logic Script Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass (CAUSE):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if CAUSE == 1:&lt;/P&gt;&lt;P&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; return 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif CAUSE == 3:&lt;/P&gt;&lt;P&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; return 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif CAUSE == 4:&lt;/P&gt;&lt;P&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; return 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&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; return 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CAUSE_RGR =&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass(!CAUSE!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However I keep getting errors. Is it a syntax issue? I can't see why something as this isn't working.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:04:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393297#M31146</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-10T18:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393298#M31147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should probably only use&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;CAUSE_RGR =&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN style="text-decoration: line-through; color: #e23d39;"&gt;def &lt;/SPAN&gt;Reclass(!CAUSE!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... so without the "def"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393298#M31147</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-10T18:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393299#M31148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the advice, but there still seems to be an issue. I removed it, but I'm still getting no result in my attribute table. I also checked the Geoprocessing Results window and it's telling me my script ran successfully, but it's not reflected in the table at all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:23:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393299#M31148</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-10T18:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393300#M31149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;... and you don't have a small selection activated of your table? (Field Calculator works on selections). I am going to create a test dataset with some value to see if I can reproduce this. What version of ArcGIS for Desktop are you using?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:28:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393300#M31149</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-10T18:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393301#M31150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I just figured it out! The problem is that although I was using numbers from the original "CAUSE" field, I forgot I had set the entire field to be a string, so it should look like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass (CAUSE):&lt;/P&gt;&lt;P&gt;&amp;nbsp; if CAUSE == "1":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 7&lt;/P&gt;&lt;P&gt;&amp;nbsp; elif CAUSE == "3":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/P&gt;&lt;P&gt;&amp;nbsp; elif CAUSE == "4":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With quotation marks. Silly me! Thank you for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:31:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393301#M31150</guid>
      <dc:creator>DeidreA</dc:creator>
      <dc:date>2015-07-10T18:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393302#M31151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Strange... seems to work just fine:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/116473_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... with this result:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/116474_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:33:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393302#M31151</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-10T18:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393303#M31152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad you resolved it. The datatype of the field has a large influence over the interpretation of the values (strings in this case).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 18:34:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393303#M31152</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-07-10T18:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to reclassify a field in attribute table with Python in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393304#M31153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander is correct, you never call a function with 'def' attached.&amp;nbsp; It is also a good idea to check your syntax and issues by running a script outside of arcmap in an python IDE.&amp;nbsp; Substitute possible values in your test def using the fieldname as the incrementer remembering to add ! before and after in the field calculator.&amp;nbsp; Now here is your example...but you will see that it will soon become ridiculous in length if there are many cases in your CAUSE's and you would be advised to examine other data structures to facilitate logic and access to reclassification (for example dictionaries etc etc).&amp;nbsp; BUT that is not the issue here... Just make sure that you don't get Lost in your CAUSE syntax &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def fld_reclass (case):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if case == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 7
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif case == 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif case == 4:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
possible = [-1,0,1,2,3,4,5]
for CAUSE in possible:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # if it helps, use your fieldname as the incrementer
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = fld_reclass(CAUSE)&amp;nbsp; # now don't forget the !_before&amp;amp;after_!
&amp;nbsp;&amp;nbsp;&amp;nbsp; print("case {}&amp;nbsp; result {}".format(CAUSE,result))
# &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:01:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-reclassify-a-field-in-attribute-table/m-p/393304#M31153</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T18:01:49Z</dc:date>
    </item>
  </channel>
</rss>

