Calculate fields with parsed attributes from one field

565
7
Jump to solution
05-11-2022 06:38 AM
ABishop
MVP Regular Contributor

I hope somebody can help with this!

Basically, I have a table with a situs address field and  I want to use this field to calculate new fields I have created which are named respectively "HouseNumber", "FullStreetName", "PrefixDirection", "StreetName", and "SuffixType".  I am thinking this is a parse function of some sort?  

See attached pics of the table I want to populate vs. the table that is already populated.  I would do this manually, but I have 96K records to edit.

ABishop_0-1652276209060.png

ABishop_1-1652276295188.png

 

 

Amanda Bishop, GISP
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Oops, missed a dot in my answer, I edited it.

!SITUS_1!.split(" ")[0]


Have a great day!
Johannes

View solution in original post

7 Replies
JohannesLindner
MVP Frequent Contributor

If the format is the same for each address, it's really easy.

You can do it with the field calculator:

 

# field calculation for HouseNumber
# Python
!FullStreetName!.split(" ")[0]

# other fields are analogous, just use different indexes

 

 

Or you can do it all at once with an UpdateCursor:

 

with arcpy.da.UpdateCursor("AdressLayer", ["SITUS_1", "HouseNumber", "FullStreetName", "PrefixDirection", "StreetName", "SuffixType"]) as cursor:
    for row in cursor:
        situs = row[0]
        number, dir, name, type = situs.split(" ")
        full_name = " ".join([dir, name, type])
        new_row = [situs, number, full_name, dir, name, type]
        cursor.updateRow(new_row)
        

 


Have a great day!
Johannes
ABishop
MVP Regular Contributor

Hello Johannes,

I would like to use the field calculator.  I tried this calc in the "HouseNumber" field:

!SITUS_1!split(" ")[0]

It didn't work.  any ideas?

Amanda Bishop, GISP
0 Kudos
JohannesLindner
MVP Frequent Contributor

Oops, missed a dot in my answer, I edited it.

!SITUS_1!.split(" ")[0]


Have a great day!
Johannes
ABishop
MVP Regular Contributor

Thank you!

Amanda Bishop, GISP
0 Kudos
ABishop
MVP Regular Contributor

Only... how do I get the next set of text?  For instance for "FullStreetName" I need the text "SW 125TH TER" from the string "9995 SW 125TH TER".

Amanda Bishop, GISP
0 Kudos
JohannesLindner
MVP Frequent Contributor
# HouseNumber
!SITUS_1!.split(" ")[0]

# PrefixDirection
!SITUS_1!.split(" ")[1]

# StreetName
!SITUS_1!.split(" ")[2]

# Street Type
!SITUS_1!.split(" ")[3]

# FullStreetName is a little different: split by space, take everything except the first element (the house number) and join by space
" ".join(!SITUS_1!.split(" ")[1:])

Have a great day!
Johannes
ABishop
MVP Regular Contributor

it worked!  Thanks!

Amanda Bishop, GISP
0 Kudos