<?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: Remove unwanted numbers and characters from attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1495393#M70872</link>
    <description>&lt;P&gt;There could be extra internal whitespace in your values e.g. "HIGHWAY••DISTRICT•#4" which wouldn't be removed by .strip(). To get around this chain the comparisons:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def dump_stuff(val):
    """Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
    if isinstance(val, str):
        if 'HIGHWAY' and 'DISTRICT' and '#4' in val.strip():
            return val  # Keep "HIGHWAY DISTRICT #4" unchanged
        else:
            return "".join([i for i in val if not (i.isdigit() or i == '#')])
    return val&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also just remove all whitespace and focus only on the characters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def dump_stuff(val):
    """Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
    if isinstance(val, str):
        if val.replace(" ", "") == 'HIGHWAYDISTRICT#4':
            return val  # Keep "HIGHWAY DISTRICT #4" unchanged
        else:
            return "".join([i for i in val if not (i.isdigit() or i == '#')])
    return val&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2024 15:17:24 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2024-06-20T15:17:24Z</dc:date>
    <item>
      <title>Remove unwanted numbers and characters from attributes</title>
      <link>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1492881#M70829</link>
      <description>&lt;P&gt;I have some fields that I need to remove the # and numbers, but I need to keep one that matches exactly HIGHWAY DISTRICT #4. I can't seem to get to bypass "HIGHWAY DISTRICT #4". When I run my code, it removes the #4 from HIGHWAY DISTRICT #4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import time

fc3 = r"C:\Default.gdb\Table_1"
fld = ['FireDist', 'HighwayDist', 'SchoolDist']

def dump_stuff(val):
    """Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
    if isinstance(val, str):
        if val.strip() == "HIGHWAY DISTRICT #4":
            return val  # Keep "HIGHWAY DISTRICT #4" unchanged
        else:
            return "".join([i for i in val if not (i.isdigit() or i == '#')])
    return val

start_time = time.time()  # Record the start time

with arcpy.da.UpdateCursor(fc3, fld) as cursor:
    for row in cursor:
        # Process each field in the row
        new_row = [dump_stuff(val) for val in row]
        cursor.updateRow(new_row)

end_time = time.time()  # Record the end time
elapsed_time = end_time - start_time

minutes, seconds = divmod(elapsed_time, 60)
print(f"Process time: {int(minutes)} minutes {int(seconds)} seconds")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 18:03:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1492881#M70829</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2024-06-14T18:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Remove unwanted numbers and characters from attributes</title>
      <link>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1492996#M70831</link>
      <description>&lt;LI-CODE lang="python"&gt;a = ["HIGHWAY DISTRICT #4 "," HIGHWAY DISTRICT #4", " HIGHWAY DISTRICT #4 "]

for i in a:
    print(i.strip())
    
HIGHWAY DISTRICT #4
HIGHWAY DISTRICT #4
HIGHWAY DISTRICT #4

for i in a:
    if "HIGHWAY DISTRICT #4" in i:
        print(i)
        
HIGHWAY DISTRICT #4 
 HIGHWAY DISTRICT #4
 HIGHWAY DISTRICT #4&lt;/LI-CODE&gt;&lt;P&gt;it should work.... check your input with a print statement or something to see if does match&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 19:44:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1492996#M70831</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-06-14T19:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Remove unwanted numbers and characters from attributes</title>
      <link>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1495393#M70872</link>
      <description>&lt;P&gt;There could be extra internal whitespace in your values e.g. "HIGHWAY••DISTRICT•#4" which wouldn't be removed by .strip(). To get around this chain the comparisons:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def dump_stuff(val):
    """Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
    if isinstance(val, str):
        if 'HIGHWAY' and 'DISTRICT' and '#4' in val.strip():
            return val  # Keep "HIGHWAY DISTRICT #4" unchanged
        else:
            return "".join([i for i in val if not (i.isdigit() or i == '#')])
    return val&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also just remove all whitespace and focus only on the characters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def dump_stuff(val):
    """Remove unwanted characters from fields except 'HIGHWAY DISTRICT #4'"""
    if isinstance(val, str):
        if val.replace(" ", "") == 'HIGHWAYDISTRICT#4':
            return val  # Keep "HIGHWAY DISTRICT #4" unchanged
        else:
            return "".join([i for i in val if not (i.isdigit() or i == '#')])
    return val&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 15:17:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-unwanted-numbers-and-characters-from/m-p/1495393#M70872</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-06-20T15:17:24Z</dc:date>
    </item>
  </channel>
</rss>

