<?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 Python code to replace individual characters using field calculator in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129541#M49436</link>
    <description>&lt;P&gt;I need to replace the 3rd and 4th digits of street addresses with 'X' and strip any apt info from the end.&lt;/P&gt;&lt;P&gt;Fer example "1756 Cedar St 4D' should become 17XX Cedar St&lt;/P&gt;&lt;P&gt;The closest I've come is:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1!.replace('0123456789','X')[2:3]&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1![2:3].replace('0123456789','X')&lt;/LI-CODE&gt;&lt;P&gt;but those just seems to turn the entire address into a single digit number&lt;/P&gt;&lt;P&gt;To remove the apartments, I got as far as removing numbers at the end using&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1!.rstrip('0123456789')&lt;/LI-CODE&gt;&lt;P&gt;but that still leaves lettered apartment units&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 2.8 and Python 3&lt;/P&gt;</description>
    <pubDate>Wed, 29 Dec 2021 20:08:08 GMT</pubDate>
    <dc:creator>MattCotterill</dc:creator>
    <dc:date>2021-12-29T20:08:08Z</dc:date>
    <item>
      <title>Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129541#M49436</link>
      <description>&lt;P&gt;I need to replace the 3rd and 4th digits of street addresses with 'X' and strip any apt info from the end.&lt;/P&gt;&lt;P&gt;Fer example "1756 Cedar St 4D' should become 17XX Cedar St&lt;/P&gt;&lt;P&gt;The closest I've come is:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1!.replace('0123456789','X')[2:3]&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1![2:3].replace('0123456789','X')&lt;/LI-CODE&gt;&lt;P&gt;but those just seems to turn the entire address into a single digit number&lt;/P&gt;&lt;P&gt;To remove the apartments, I got as far as removing numbers at the end using&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;!USER_Address_Line_1!.rstrip('0123456789')&lt;/LI-CODE&gt;&lt;P&gt;but that still leaves lettered apartment units&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 2.8 and Python 3&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 20:08:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129541#M49436</guid>
      <dc:creator>MattCotterill</dc:creator>
      <dc:date>2021-12-29T20:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129554#M49441</link>
      <description>&lt;P&gt;Thy the following expression&lt;/P&gt;&lt;P&gt;Expression Type: Python 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;(!USER_Address_Line_1![0:-2])[:2]+'XX'+(!USER_Address_Line_1![0:-2])[4:]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="python"&gt;((!Micromarket![0:-2])[:2]+'XX'+(!Micromarket![0:-2])[4:]).strip()&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Dec 2021 20:36:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129554#M49441</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2021-12-29T20:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129571#M49446</link>
      <description>&lt;P&gt;or generically... you can add the length check if you want&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fld = '1756 Cedar St 4D'  # !fld!  or !YourFieldName! for the expression
def r(fld, subval="X"):
    """ """
    new = []
    vals = fld.split(" ")
    for v in vals:
        for i in v:
            s = "".join([subval if i in "0123456789" else i for i in v])
        new.append(s)
    new = " ".join(new)
    return new

# -- test
r(fld)
'XXXX Cedar St XD'&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Dec 2021 21:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129571#M49446</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-29T21:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129661#M49457</link>
      <description>&lt;P&gt;Thank you! In terms of what I need for this data set, this absolutely works. I'm curious how you would handle it if you needed to keep the street types (RD, AVE, BLVD, CT, TER, etc.) and not all addresses had apartments. Can you run an if/then loop in field calculator?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 16:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129661#M49457</guid>
      <dc:creator>MattCotterill</dc:creator>
      <dc:date>2021-12-30T16:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129665#M49458</link>
      <description>&lt;P&gt;Thank you! This is a little over my head, but I feel like this is something I need to understand. By "generically" do you mean outside the field calculator environment, using a Python interpreter? And is that how I would run this script on a csv file?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 17:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129665#M49458</guid>
      <dc:creator>MattCotterill</dc:creator>
      <dc:date>2021-12-30T17:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to replace individual characters using field calculator</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129671#M49460</link>
      <description>&lt;P&gt;By "generically" it just doesn't replace 2 characters that are numbers but will replace any number whether it is a street address or an apartment number... even if there is no apartment.&amp;nbsp; The only issue is if you had a&lt;/P&gt;&lt;P&gt;"1st Avenue"&amp;nbsp;&lt;/P&gt;&lt;P&gt;it would become "Xst Avenue"&lt;/P&gt;&lt;P&gt;This is a code block example&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field-examples.htm" target="_blank"&gt;Calculate Field Python examples—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;They are handy when a one-liner is too constrictive&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 17:42:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-to-replace-individual-characters-using/m-p/1129671#M49460</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-30T17:42:27Z</dc:date>
    </item>
  </channel>
</rss>

