<?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: ModelBuilder Calculate Field in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800980#M2751</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your expression block should be:&lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;cat = Reclass(!yield!)&lt;/PRE&gt;&lt;SPAN&gt; Otherwise you'd be trying to read an integer from a string field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Mar 2012 12:59:58 GMT</pubDate>
    <dc:creator>BruceNielsen</dc:creator>
    <dc:date>2012-03-01T12:59:58Z</dc:date>
    <item>
      <title>ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800978#M2749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using ModelBuilder to create a new field ([cat]) that will contain category values based on range criteria of another field ([yield]).&amp;nbsp; I would like to use the Python parser.&amp;nbsp; HEre is what I have so far in the Pre-Logic Script Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def Reclass(yield) :
&amp;nbsp; if (yield &amp;lt;=140) :
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Low"
&amp;nbsp; elif (yield &amp;gt; 140 and yield &amp;lt;= 180) :
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Average"
&amp;nbsp; elif (yield &amp;gt; 180) :
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the expression block I have cat = Reclass(!cat!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get a red "X" in the calculate Field dialog stating there is a parse error on line 1.&amp;nbsp; Any ideas as to what I'm doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:17:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800978#M2749</guid>
      <dc:creator>WadeGivens</dc:creator>
      <dc:date>2021-12-12T09:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800979#M2750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;you can't use yield it is a reserved word&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;also what you posted doesn't see complete&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def Reclass(x):
&amp;nbsp; if (x &amp;lt;=140):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Low"
&amp;nbsp; elif (x &amp;gt; 140 and x &amp;lt;= 180):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Average"
&amp;nbsp; elif (x &amp;gt; 180):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return "High"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800979#M2750</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2021-12-12T09:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800980#M2751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your expression block should be:&lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;cat = Reclass(!yield!)&lt;/PRE&gt;&lt;SPAN&gt; Otherwise you'd be trying to read an integer from a string field.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Mar 2012 12:59:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800980#M2751</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-03-01T12:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800981#M2752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Your expression block should be:&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;cat = Reclass(!yield!)&lt;/PRE&gt; Otherwise you'd be trying to read an integer from a string field.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Yield" within the function still needs to be changed as well, but you are right you can't pass a string when the function is looking for a number.&amp;nbsp; Therefore cat = Reclass(!cat!) should be changed to cat = Reclass(!nameOfFieldwithNumbericValue!) unless cat is the field with the numeric value; in that case it should be nameOfFieldWithStringValue = Reclass(!Cat!)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Mar 2012 18:13:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800981#M2752</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2012-03-01T18:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800982#M2753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or perhaps &amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;cat &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; Reclass&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!cat!&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# --- If you need to use the cat value and overwrite the string number with text&lt;/SPAN&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# --- Then you would also have to account for possible non numbers text in the Reclass def?‍‍‍‍‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:17:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800982#M2753</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2021-12-12T09:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: ModelBuilder Calculate Field</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800983#M2754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The expression for the Calculate Field tool should simply be (if "cat" is your field name). CAT is also then entered in the Field argument to Calculate Field.&lt;/P&gt;&lt;P&gt;Ted is correct that you'd want to account for non-covered fields. Seems to me it would be safer to create a new field and calculate to that in case something goes wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;Reclass&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!CAT!&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Oct 2016 01:53:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/modelbuilder-calculate-field/m-p/800983#M2754</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2016-10-29T01:53:00Z</dc:date>
    </item>
  </channel>
</rss>

