<?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: Calculate field string into int and float =&amp;gt; error in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795317#M1070</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to covert the first column into the last (string to numeric).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attempted the Replace because I thought I could simplify it but, as you pointed out.....I did not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot convert them to 0 because it will false my analysis (they are temp and other values)&lt;/P&gt;&lt;P&gt;I need a NO VALUE&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 07 Oct 2019 13:44:22 GMT</pubDate>
    <dc:creator>PanGIS</dc:creator>
    <dc:date>2019-10-07T13:44:22Z</dc:date>
    <item>
      <title>Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795313#M1066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am running a model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. for field 1(string)&amp;nbsp; I have "integer numbers" and a value "nan"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;I use field calc with the expression:&amp;nbsp;!ACmodeString!.replace("nan","&amp;lt;Null&amp;gt;")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Once I have the null records I run&amp;nbsp; again Filed Calc to copy these values from the string field into a integer field with a expression like Field1(string) = Field2(integer) &amp;nbsp; [ I have tried both VB and Python]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a. with python I get this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 999999: Error executing function.&lt;BR /&gt;The value type is incompatible with the field type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;b. with python again&lt;/P&gt;&lt;P&gt;int(!acmodestring!)&lt;/P&gt;&lt;P&gt;erro:&lt;/P&gt;&lt;DIV&gt;ERROR 000539: Error running expression: int(u"&amp;lt;Null&amp;gt;") &lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;ValueError: invalid literal for int() with base 10: '&amp;lt;Null&amp;gt;'&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c. with VB I get an alert:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/461273_errorFC.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I click yes it finishes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the same happens for a filed that needs to be converted in float.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to get rid of this alert.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue seems to be the null value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Oct 2019 15:11:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795313#M1066</guid>
      <dc:creator>PanGIS</dc:creator>
      <dc:date>2019-10-06T15:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795314#M1067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;nan does not exist for integers, only float values.&amp;nbsp; You should show the table that you are working with.&amp;nbsp; The field is either text or float&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Oct 2019 16:18:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795314#M1067</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-10-06T16:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795315#M1068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did not explained myself well.&lt;/P&gt;&lt;P&gt;The original table has a field (string type) with numbers and some "nan" values.&lt;/P&gt;&lt;P&gt;When I say nan I mean the word "nan".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I need to convert this values into numbers I remove the word nan by using the python exp.:&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;!ACmodeString!.replace("nan","&amp;lt;Null&amp;gt;").&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Now I have that string field populated by numbers and &amp;lt;Null&amp;gt; records.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;What I need to do is to&amp;nbsp; convert all these values into integer in a new field (short type).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I'll try to upload some data as soon as possible.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Here a not very nice example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/461215_Screenshot_20191006-224639.jpg" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Oct 2019 20:55:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795315#M1068</guid>
      <dc:creator>PanGIS</dc:creator>
      <dc:date>2019-10-06T20:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795316#M1069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Regarding&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Since I need to convert this values into numbers I remove the word nan by using the python exp.:&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;!ACmodeString!.replace("nan","&amp;lt;Null&amp;gt;").&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The Python expression above hasn't changed "nan" to Null, it has changed "nan" to "&amp;lt;Null&amp;gt;".&amp;nbsp; What you have done is changed the string value to another string value with the characters that spell out Null, is isn't actually Null.&amp;nbsp; If you open the Select Layer By Attribute tool and query the table like, "field IS NULL" (use actual field name), you will see no records are selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you want the "nan" records to get converted and stay NULL, or do you want to eventually change them to some number like 0, -9999, etc....?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Oct 2019 21:18:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795316#M1069</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-10-06T21:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795317#M1070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to covert the first column into the last (string to numeric).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I attempted the Replace because I thought I could simplify it but, as you pointed out.....I did not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot convert them to 0 because it will false my analysis (they are temp and other values)&lt;/P&gt;&lt;P&gt;I need a NO VALUE&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Oct 2019 13:44:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795317#M1070</guid>
      <dc:creator>PanGIS</dc:creator>
      <dc:date>2019-10-07T13:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795318#M1071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found the answer here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" class="link-titled" href="https://community.esri.com/thread/51894#comment-579306" title="https://community.esri.com/thread/51894#comment-579306"&gt;https://community.esri.com/thread/51894#comment-579306&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Oct 2019 10:20:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795318#M1071</guid>
      <dc:creator>PanGIS</dc:creator>
      <dc:date>2019-10-17T10:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field string into int and float =&gt; error</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795319#M1072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found it hard to find the answer in the linked post, so for the good of the thread:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's&amp;nbsp;a Python&amp;nbsp;expression for Calculate&amp;nbsp;Field to replace the string "nan" to null in a string field. This solution uses a very handy (but IMHO not terribly Pythonic) construct known as a t&lt;A href="https://www.geeksforgeeks.org/ternary-operator-in-python/"&gt;ernary operator&lt;/A&gt;. Thanks &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;‌ for turning me on to these, they are&amp;nbsp;&lt;EM&gt;very&lt;/EM&gt; helpful when doing field calculations!&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;!ACmodeString! &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; !ACmodeString! &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"nan"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; None‍‍‍&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>Sun, 20 Oct 2019 16:07:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/calculate-field-string-into-int-and-float-gt-error/m-p/795319#M1072</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2019-10-20T16:07:03Z</dc:date>
    </item>
  </channel>
</rss>

