I have a shapefile with polygons and each polygon has an ID number that follows a pattern like this:
SMP_ID
1077-1-1
8-2-2
1281-1-3
304-2-1
In have created a new field and I need to populate it with a truncated version of these IDs, which would look like this:
SYS_ID
1077-1
8-2
1281-1
304-2
This is the code I've been fiddling with most recently, I feel like it's the closest...
def getSysID(SMP_ID):
if SMP_ID is None:
return None
else:
SysID = SMP_ID.split('-')[0] + '-' + SMP_ID.split('-')[1]
return SysID
I also tried this method:
id_vals = !SMP_ID!.split("-")
SYS_ID = id_vals[0] + "-" + id_vals[1]
remainder = id_vals[2]
Something isn't working right, though! There are a few IDs from a different source that don't follow this pattern and are just a string of numbers without hyphens, I'm wondering if that could be a part of the problem?
I'm looking for a solution that will ignore the non-hyphenated IDs and nulls, and copy the truncated hyphenated IDs into a new field.