<?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 expression question! in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629894#M21041</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again Bruce, &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!fieldname!.split()[-1]&lt;/PRE&gt;&lt;SPAN&gt; worked excellently in the field calculator!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Aug 2011 17:14:32 GMT</pubDate>
    <dc:creator>SeanKroencke</dc:creator>
    <dc:date>2011-08-02T17:14:32Z</dc:date>
    <item>
      <title>Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629886#M21033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a field that has City, State, Zip in it. I'd like a new field with the zip code only in it, and then I'd like to be able to remove the zip from the original field. Is there a way to do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Possibly an expression that removes all #'s?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jul 2011 15:17:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629886#M21033</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-07-28T15:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629887#M21034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First, read this &lt;/SPAN&gt;&lt;A href="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2010/08/30/Concatenate.aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;blog post&lt;/A&gt;&lt;SPAN&gt; about concatenating fields using the Calculate Field tool.&amp;nbsp; It explains how to create a Python routine for Calculate Field to run to fetch a new field value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Assuming you're dealing with 5-digit zip U.S. zip codes, and that the zip code falls at the end of the address, here's a snippet that shows one way you can parse it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; address = "380 New York St Redlands Ca 92373&amp;nbsp; "&amp;nbsp; # Note: trailing blanks
&amp;gt;&amp;gt;&amp;gt; address = address.strip()&amp;nbsp; # get rid of leading/trailing blanks
&amp;gt;&amp;gt;&amp;gt; print address
380 New York St Redlands Ca 92373

&amp;gt;&amp;gt;&amp;gt; length_of_address = len(address)&amp;nbsp; # number of characters
&amp;gt;&amp;gt;&amp;gt; print length_of_address
33

&amp;gt;&amp;gt;&amp;gt; zip = address[length_of_address - 5: length_of_address]&amp;nbsp; # Get last 5 digits
&amp;gt;&amp;gt;&amp;gt; print zip
92373

&amp;gt;&amp;gt;&amp;gt; stripped_address = address[0:length_of_address - 5]&amp;nbsp; # everything up to zip code
&amp;gt;&amp;gt;&amp;gt; print stripped_address
380 New York St Redlands Ca 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629887#M21034</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-12T02:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629888#M21035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Another alternative would be to use zip = address.strip()[-1]. That will return the last set of non-whitespace characters in the address string, regardless of length. You could then use slicing with rfind to get the first portion of the string:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; address = "380 New York St Redlands Ca 92373&amp;nbsp; "
&amp;gt;&amp;gt;&amp;gt; zip = address.split()[-1]
&amp;gt;&amp;gt;&amp;gt; zip
'92373'
&amp;gt;&amp;gt;&amp;gt; address[:address.rfind(zip)]
'380 New York St Redlands Ca '&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629888#M21035</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2021-12-12T02:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629889#M21036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for both of your replies! I failed to mention in my haste that some of the entries have not only the 5 digit US ZIP code but have the 4 digit ZIP tagged on at the end as well, for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Town, NY 12345-1234"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bruce, by last set of non-whitespace characters characters, what do you mean? I'm utterly inexperienced at coding/programming, pardon the questions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 13:43:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629889#M21036</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-07-29T13:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629890#M21037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Whitespaces are spaces, tabs, etc. When using the split method without any parameters, it also removes those extra characters from the end of the string. Technically, the split method creates a Python list of items from a string based on a delimiter character in the string. The default is a space. Since you only want the last item in that list (the zip code), the [-1] is added to tell Python to only return the last item in the list that split created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to learn more, start with the tutorial that is included with Python's help. IMHO it's a good place to get familiar with what Python can do as far as string manipulation.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 14:04:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629890#M21037</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2011-07-29T14:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629891#M21038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That would work perfectly! Do I need to replace where you have "address" with the name of the field that has the address in it, or am I NOT doing this calculation in a new blank field. I'm thinking that this is a calculation done within the same field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do I include the &amp;gt;&amp;gt;&amp;gt;'s?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will certainly check out the tutorial for Python. Is that located within ArcGIS or separately? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; address = "380 New York St Redlands Ca 92373&amp;nbsp; "
&amp;gt;&amp;gt;&amp;gt; zip = address.split()[-1]
&amp;gt;&amp;gt;&amp;gt; zip
'92373'
&amp;gt;&amp;gt;&amp;gt; address[:address.rfind(zip)]
'380 New York St Redlands Ca '&lt;/PRE&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 02:48:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629891#M21038</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2021-12-12T02:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629892#M21039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't normally use Python within the Calculate Field tool, but I think you would use an expression like !&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;fieldname&lt;/SPAN&gt;&lt;SPAN&gt;!.split()[-1], where &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;fieldname&lt;/SPAN&gt;&lt;SPAN&gt; is the column with your existing city/state/zip string. The blog post that Dale referenced should provide enough details to get you started.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The '&amp;gt;&amp;gt;&amp;gt;' are prompts from Python's interactive interpreter. Don't include those in your code. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Python Help is found under Python 2.x as Python Manuals if you're using ArcGIS 9.x. For ArcGIS 10, I think you go to ArcGIS, then Python 2.x, then look for the help docs.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jul 2011 14:46:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629892#M21039</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2011-07-29T14:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629893#M21040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good one, Bruce.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; address = "380 New York St Redlands Ca 92373&amp;nbsp; "
&amp;gt;&amp;gt;&amp;gt; zip = address.split()[-1]
&amp;gt;&amp;gt;&amp;gt; zip
'92373'
&amp;gt;&amp;gt;&amp;gt; address[:address.rfind(zip)]
'380 New York St Redlands Ca '&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:48:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629893#M21040</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-12T02:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629894#M21041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks again Bruce, &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;!fieldname!.split()[-1]&lt;/PRE&gt;&lt;SPAN&gt; worked excellently in the field calculator!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 17:14:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629894#M21041</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-08-02T17:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629895#M21042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Any advice on how I can do the same technique to REMOVE the ZIP at the end, so I have a field that's just the City, State?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 18:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629895#M21042</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-08-02T18:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629896#M21043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this, after you have extracted the zip code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;!fieldname![:!fieldname!.rfind(!newzipfield!)].strip()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The .strip() is to get rid of any spaces that were between the state and zip code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 18:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629896#M21043</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2011-08-02T18:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629897#M21044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Another win, thanks so much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Aug 2011 19:16:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629897#M21044</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-08-02T19:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629898#M21045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have another dataset that I'm trying to perform these calculations on.. however the formatting in this dataset is not uniform. There are sporadic spaces, punctuation, and repeats of state abbreviations, etc. Is there a python method to remove numbers, only show numbers, remove letters, etc.?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2011 14:31:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629898#M21045</guid>
      <dc:creator>SeanKroencke</dc:creator>
      <dc:date>2011-08-22T14:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator expression question!</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629899#M21046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your best bet is to start browsing the different string methods that are available. These are your building blocks for manipulating strings. That way you can start building your own solutions to these problems as they arise.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the on-line documentation (for version 2.7) they are found in &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange"&gt;section 5.6.1&lt;/A&gt;&lt;SPAN&gt;. In my local help document (ver. 2.4) it is section 2.3.6.1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Aug 2011 16:21:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calculator-expression-question/m-p/629899#M21046</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2011-08-22T16:21:34Z</dc:date>
    </item>
  </channel>
</rss>

