<?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 Reclass Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193232#M14833</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm running it with python checked, but I'm not sure which advanced tab you're referring to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code runs, but it's still not updating the field. Is there a specific way that a float value needs to be written?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def Reclass(N_Value, LUCode):
&amp;nbsp; if LUCode == "Pasture":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.050
&amp;nbsp; elif LUCode == "Greenspace":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Forest":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.08
&amp;nbsp; elif LUCode == "Urban":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Brush":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.060
&amp;nbsp; elif LUCode == "Grass":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Clean, straight":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.030
&amp;nbsp; elif LUCode == "Clean, winding":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Straight, weeds/stones":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.040

Reclass(!N_Value!, !LUCode!)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 09:41:42 GMT</pubDate>
    <dc:creator>SamNeale</dc:creator>
    <dc:date>2021-12-11T09:41:42Z</dc:date>
    <item>
      <title>Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193230#M14831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to assign a float value to field N_Value, based on the string value in field LUCode.&amp;nbsp; My code runs without errors, but isn't making any changes in the attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
def Reclass(N_Value, LUCode):
&amp;nbsp; if LUCode == "Pasture":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.050
&amp;nbsp; elif LUCode == "Greenspace":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Forest":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.08
&amp;nbsp; elif LUCode == "Urban":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Brush":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.060
&amp;nbsp; elif LUCode == "Grass":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Clean, straight":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.030
&amp;nbsp; elif LUCode == "Clean, straight":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Straight, weeds/stones":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.040
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Done."


Reclass(!N_Value!, !LUCode!)
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 20:07:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193230#M14831</guid>
      <dc:creator>SamNeale</dc:creator>
      <dc:date>2012-08-30T20:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193231#M14832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd remove your print statement. I'm not sure what that would do in a field calculator. Also are you using the advanced tab and calculating with python option? Try loading this and see if it does it for you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 20:19:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193231#M14832</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-08-30T20:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193232#M14833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm running it with python checked, but I'm not sure which advanced tab you're referring to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code runs, but it's still not updating the field. Is there a specific way that a float value needs to be written?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def Reclass(N_Value, LUCode):
&amp;nbsp; if LUCode == "Pasture":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.050
&amp;nbsp; elif LUCode == "Greenspace":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Forest":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.08
&amp;nbsp; elif LUCode == "Urban":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.04
&amp;nbsp; elif LUCode == "Brush":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.060
&amp;nbsp; elif LUCode == "Grass":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Clean, straight":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.030
&amp;nbsp; elif LUCode == "Clean, winding":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.035
&amp;nbsp; elif LUCode == "Straight, weeds/stones":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0.040

Reclass(!N_Value!, !LUCode!)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:41:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193232#M14833</guid>
      <dc:creator>SamNeale</dc:creator>
      <dc:date>2021-12-11T09:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193233#M14834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In the field calculator window there is a checkbox called show codeblock, that needs to be checked and your code needs to be split between the two boxes. If the example I sent you isn't working though I'm not sure what the issue is.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 20:40:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193233#M14834</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-08-30T20:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193234#M14835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'm trying to assign a float value to field N_Value, based on the string value in field LUCode.&amp;nbsp; My code runs without errors, but isn't making any changes in the attribute table.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would avoid passing N_Value to the function; you're not using it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You also may want to consider using a dictionary instead - just nicer, faster code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The try/except will cause the function return null if there is no match to your list of lucode values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Calculate Value&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expr: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;Reclass(!LUCode!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def Reclass(lucode):
&amp;nbsp; dict = {
&amp;nbsp; "Pasture"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.050&amp;nbsp; ,
&amp;nbsp; "Greenspace"&amp;nbsp; : 0.04&amp;nbsp;&amp;nbsp; ,
&amp;nbsp; "Forest"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.08&amp;nbsp;&amp;nbsp; ,
&amp;nbsp; ...
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return dict[lucode]
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:41:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193234#M14835</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T09:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193235#M14836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh, yeah I have that on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for trying.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 20:43:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193235#M14836</guid>
      <dc:creator>SamNeale</dc:creator>
      <dc:date>2012-08-30T20:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Reclass Python</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193236#M14837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, it worked!&amp;nbsp; I had tried using a dictionary command before, but I didn't do it right I guess.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 20:49:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-reclass-python/m-p/193236#M14837</guid>
      <dc:creator>SamNeale</dc:creator>
      <dc:date>2012-08-30T20:49:25Z</dc:date>
    </item>
  </channel>
</rss>

