Parse out a word from a field in field calculator

2152
4
Jump to solution
09-11-2014 12:28 PM
StevenHeadley
New Contributor II

I have a field called Address.  And example of a record in that field is 900 Main St.  I need to get "Main" into a field called Street Name.  I already parsed out the street number(900) and the street type (St), but can't figure out how to do the name.  I'm working in ArcMap, so I would like to do it right in the table field calculator.  I have over 7,000 records I need to do this to.

Thanks

0 Kudos
1 Solution

Accepted Solutions
AnthonyGiles
Frequent Contributor

Steven,

I had more of a thought about this and to make it more robust it would be better to use the following python snippet:

def convertName(address):

  newname = ""

  newaddress = address.split(" ")

  for word in range(1,len(newaddress) -1):

    newname = newname + newaddress[word] + " "

  return newname[:-1]

to use in the field calculator follow the screenshot:

View solution in original post

4 Replies
AnthonyGiles
Frequent Contributor

If you are using the field calculator, switch the parser to python and use the following:

!address!.split(" ")[1]

what this does is split the address field each time there is a space then uses the second item in the array (the array is zero based), it will only work if your address are all in the format of number streetname streettype.

if you have street names with more spaces in then you will need to do some combination of if statements on the length of the array to handle the results, let me know if you need more advice

AnthonyGiles
Frequent Contributor

Steven,

I had more of a thought about this and to make it more robust it would be better to use the following python snippet:

def convertName(address):

  newname = ""

  newaddress = address.split(" ")

  for word in range(1,len(newaddress) -1):

    newname = newname + newaddress[word] + " "

  return newname[:-1]

to use in the field calculator follow the screenshot:

StevenHeadley
New Contributor II

Thanks Anthony! I know very little about scripting, but this was great. Just saved me tons of time.

0 Kudos
AnthonyGiles
Frequent Contributor

No problem Steven, please return the favour by marking my post as the correct answer and helpful

0 Kudos