<?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/strip certain text/string from rows in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587875#M46086</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with &lt;A href="https://community.esri.com/migrated-users/4422"&gt;Joe Borgione&lt;/A&gt;‌ on several points.&amp;nbsp; Firstly, actual sample data never hurts.&amp;nbsp; Secondly, and more importantly, address parsing is notoriously complex, and there is no reason to reinvent wheels that already work well.&amp;nbsp; There are several US address parsing libraries, I suggest you use one of those.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Oct 2020 03:30:42 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2020-10-22T03:30:42Z</dc:date>
    <item>
      <title>Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587871#M46082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How can I remove certain text/string from all the rows in a filed with out having to do multiple updatcursors?&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I need to remove the city and state from each row if there is no city and state just skip and keep going, some may not have any city and state .&lt;/LI&gt;&lt;LI&gt;The city and stats might be different for each row.&lt;/LI&gt;&lt;LI&gt;The state and city will always be at the end which would be :13. Some how I need to just work on the last 13 characters because some address use the city name.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need don't want to create another filed I just need the city and state removed from all the rows of a certain field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE height="264" width="371"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;OID&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;field1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;field1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;1&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city1&amp;nbsp; state1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;2&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city2&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;3&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city3&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;4&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city2&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;5&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city4&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;6&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city5&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;7&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city5&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;8&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city1&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="width: 76.9px;"&gt;9&lt;/TD&gt;&lt;TD style="width: 178.3px;"&gt;address city2&amp;nbsp; State1&lt;/TD&gt;&lt;TD style="width: 93.8px;"&gt;address&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Was thinking something like this but I doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;fc = 'featureclass'
tx = ['City1 State','City2 State','City3 State','City4 State', 'City5 State']

with arcpy.da.UpdateCursor(fc, ['field1']) as cursor:
    for row in cursor:
        if row[0][:13] in tx:
            row[0] = row[0][:13]
            cursor.updateRow(row)
del cursor&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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, 12 Dec 2021 01:15:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587871#M46082</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-12-12T01:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587872#M46083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Potentially, you could lose your mind trying to figure out how many combinations of address, city and state your data has.&amp;nbsp; Just sayin'...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you want the last n&amp;nbsp; characters of a string you'd use:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;myString &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Some Street and City State'&lt;/SPAN&gt;
myString&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#returns State&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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, 12 Dec 2021 01:15:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587872#M46083</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-12T01:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587873#M46084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Aw I didn't think of that.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;fc = 'featureclass'
tx = ['City1 State','City2 State','City3 State','City4 State', 'City5 State']

with arcpy.da.UpdateCursor(fc, ['field1']) as cursor:
    for row in cursor:
        row[0] = " ".join(row[0].split()[:-2]) 
        cursor.updateRow(row)
del cursor‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I did notice that it did remove ones like&lt;/P&gt;&lt;P&gt;12345 StreetA St city State --&amp;gt;12345 StreetA St # What I wanted&lt;/P&gt;&lt;P&gt;0 StreetB St --&amp;gt; 0 # This is the issues, I would prefer if it just stayed 0 StreetB St.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:15:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587873#M46084</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2021-12-12T01:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587874#M46085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps you could post some of your actual data. Those variable values are really tough to standardise.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 02:45:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587874#M46085</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-10-22T02:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587875#M46086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with &lt;A href="https://community.esri.com/migrated-users/4422"&gt;Joe Borgione&lt;/A&gt;‌ on several points.&amp;nbsp; Firstly, actual sample data never hurts.&amp;nbsp; Secondly, and more importantly, address parsing is notoriously complex, and there is no reason to reinvent wheels that already work well.&amp;nbsp; There are several US address parsing libraries, I suggest you use one of those.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 03:30:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587875#M46086</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-10-22T03:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Remove/strip certain text/string from rows</title>
      <link>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587876#M46087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a &lt;A _jive_internal="true" href="https://community.esri.com/thread/163731"&gt;post of mine&lt;/A&gt; that describes some address parsing I have done in the past. &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌ provides a link to one of the parsing libraries he alludes to above&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 15:07:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/remove-strip-certain-text-string-from-rows/m-p/587876#M46087</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-10-22T15:07:50Z</dc:date>
    </item>
  </channel>
</rss>

