I have an ADDRESS field in a table with values like:

  • 1 MAIN ST
  • 20 SIDE AVE W
  • 300 JOHN DOE JR RD S

I want to use the field calculator to split the addresses and insert the parts into HOUSE_NUMBER and STREET_NAME fields. Example:

  • 300 into HOUSE_NUMBER

I also want the tool to check if the value that will be put into HOUSE_NUMBER is a valid integer (and ignore it if it isn't).

How can I do this?


This python script seems to do the trick. It allows the user to choose whether to return the house number or the street name to the field (by commenting-out the non-applicable ReturnType line).

def addressParser(inString):
    returnType = "House Number"
    #returnType = "Street Name"

    splitString = inString.split(' ',1)
    houseNumber = splitString[0]
    streetName = splitString[1]

    if returnType == "House Number":
        if houseNumber.isdigit():
            return houseNumber
    if returnType == "Street Name":
        return streetName


  • I have a related question here: How to design configurable scripts for non-programmers – Wilson Sep 3 '17 at 18:40
  • 1
    I hinted some ideas over there. – gisnside Sep 3 '17 at 19:17
  • 1
    streetName should be ' '.join(splitString[1:]) to create a string out of every word but the first otherwise the 3rd example would be just 'JOHN' rather than 'JOHN DOE JR RD S' or depending on your requirements ' '.join(splitString[1:]).title() to return 'John Doe Jr Rd S' might be suitable. Were you to run this in a python script rather than as field calculator expression you could update both values at the same time. – Michael Stimson Sep 3 '17 at 20:52
  • 2
    @MichaelStimson the code specifies that it is only splitting the string at the first space .split(' ', 1) so the code will work as written. – jbalk Sep 6 '17 at 7:10

This works for me

def format_address(address_string):
    # Declare variables
    hn =""
    ha =""
  # Separate the address string into parts
    address_string = address_string.split()
  # Traverse through the address parts
    for add in address_string:
        if add.isnumeric():
            hn += add
            ha += add + " "
    # Determine if the address part is the
    # house number or part of the street name
  # Does anything else need to be done
  # before returning the result?

  # Return the formatted string
    return "house number {} on street named {}".format(hn,ha)

print(format_address("123 Main Street"))
# Should print: "house number 123 on street named Main Street"

print(format_address("1001 1st Ave"))
# Should print: "house number 1001 on street named 1st Ave"

print(format_address("55 North Center Drive"))
# Should print "house number 55 on street named North Center Drive"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.