How can I remove certain text/string from all the rows in a filed with out having to do multiple updatcursors?
- 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 .
- The city and stats might be different for each row.
- 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.
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.
| OID | field1 | field1 |
| 1 | address city1 state1 | address |
| 2 | address city2 State1 | address |
| 3 | address city3 State1 | address |
| 4 | address city2 State1 | address |
| 5 | address city4 State1 | address |
| 6 | address city5 State1 | address |
| 7 | address city5 State1 | address |
| 8 | address city1 State1 | address |
| 9 | address city2 State1 | address |
Was thinking something like this but I doesn't work.
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<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>