Arcpy - delete attribute data if string starts with..

2569
10
Jump to solution
08-18-2014 02:12 PM
AliciaSoto
Occasional Contributor

Here's what I'm trying to do.

I have a shapefile called 'Roster' with an attribute table like the one below.

NAMEAgeRoom
***John23B
***Alice56C
Tina34A

I would like to search the shapefile and delete any data under the field 'NAME' where the string starts with '***'

The resulting table would look like this

NAMEAgeRoom
23B
56C
Tina34A

I figured out how to replace the '***' string with another string, but I can't figure out how to delete the entire cell....

def removeName(shapefilePath):

  cursor = arcpy.da.UpdateCursor(shapefilePath, ["NAME"])

  for row in cursor:

       row[0] = row[0].replace("***", None)

       cursor.updateRow(row)

  del row

  del cursor

Tags (2)
0 Kudos
10 Replies
JoshuaBixby
MVP Esteemed Contributor

Charlie Frye wrote:

Thanks Ian--I've been writing VBA lately...

An Esri staffer writing VBA?  Isn't that sacrilegious these days seeing that Esri deprecated VBA in 10.1 and has been trying unsuccessfully to retire it since then.

0 Kudos