<?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: Using Field Calculator for turning a string into an integer while removing text... in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311050#M24216</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, it was the bottom part.... I needed to make it say:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1456328975891878 jive_text_macro" data-renderedposition="33.45170211791992_7.997159004211426_872_15" jivemacro_uid="_1456328975891878"&gt;&lt;P&gt;makestr(!Layer!)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...sheesh...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks James! Again, you're the best!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Feb 2016 15:49:58 GMT</pubDate>
    <dc:creator>AdrianWelsh</dc:creator>
    <dc:date>2016-02-24T15:49:58Z</dc:date>
    <item>
      <title>Using Field Calculator for turning a string into an integer while removing text...</title>
      <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311047#M24213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I feel kind of dumb but I cannot figure out how to make this work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should be easy, I think, but field calculator is making it difficult for me. I have one field that has text and numbers. I want to use Field Calculator with Python to just grab those numbers and put them into my Long Integer field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using the example from &lt;A href="http://gis.stackexchange.com/questions/133659/extract-numbers-from-string-field"&gt;Stack Exchange&lt;/A&gt; but maybe I am doing it wrong because this example is making it a string?&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="187398" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/187398_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;(this returns nothing in my records)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 15:15:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311047#M24213</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-24T15:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Calculator for turning a string into an integer while removing text...</title>
      <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311048#M24214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to check if the list you are building contains any digits because if you return anything with only text it will bomb since the field you are calculating is type Integer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def makestr(test):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numlist = [] 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for s in test:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if s.isdigit():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numlist.append(s)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retlist = ''.join(numlist) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if any(char.isdigit() for char in retlist):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return retlist&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:52:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311048#M24214</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T14:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Calculator for turning a string into an integer while removing text...</title>
      <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311049#M24215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;James, that makes sense and I ran the codeblock in Field Calculator with your code, but it didn't return anything. There were no errors though. Is there something I am doing wrong?&lt;/P&gt;&lt;P&gt;The field that I am grabbing the values from is called "Layer" and I am putting the values into "Parcel_Numb".&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def makestr(Layer):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; numlist = []&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for s in Layer:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if s.isdigit():&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; numlist.append(s)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retlist = ''.join(numlist)&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if any(char.isdigit() for char in retlist):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return retlist&lt;/PRE&gt;&lt;P&gt;and for the bottom part:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;makestr(!Pacel_Numb!)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it a syntax issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:52:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311049#M24215</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2021-12-11T14:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Calculator for turning a string into an integer while removing text...</title>
      <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311050#M24216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, it was the bottom part.... I needed to make it say:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1456328975891878 jive_text_macro" data-renderedposition="33.45170211791992_7.997159004211426_872_15" jivemacro_uid="_1456328975891878"&gt;&lt;P&gt;makestr(!Layer!)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...sheesh...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks James! Again, you're the best!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 15:49:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311050#M24216</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-24T15:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using Field Calculator for turning a string into an integer while removing text...</title>
      <link>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311051#M24217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without code blocks, substitute&amp;nbsp; fld for your field name.&lt;/P&gt;&lt;P&gt;Since you said output is integer, then use:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; fld = "12,ab3c4g-6*"
&amp;gt;&amp;gt;&amp;gt; int("".join([i for i in fld if i.isdigit() ]))
12346
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:52:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-calculator-for-turning-a-string-into/m-p/311051#M24217</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:52:31Z</dc:date>
    </item>
  </channel>
</rss>

