Copy/Paste Certain Attributes into a new field

813
2
Jump to solution
06-28-2021 09:11 AM
Labels (3)
BennyNein
New Contributor III

Hello,

 

I was wondering if it was possible to copy only integers from an existing field in an attribute table and paste them into a newly created field into the same attribute table. Basically, I have an address field that contains the entire address (number and street name) and I would like to separate out a column specifically for the street number.  Any advice would be appreciated. Thank you!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

Via field calculation "z" represents your field, so replace it with !YourFieldName! in line 2.

Results should obviously go into an integer field

z = "123 ABC Street"
int("".join([i for i in z if i.isdigit()]))
123

  


... sort of retired...

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor

Via field calculation "z" represents your field, so replace it with !YourFieldName! in line 2.

Results should obviously go into an integer field

z = "123 ABC Street"
int("".join([i for i in z if i.isdigit()]))
123

  


... sort of retired...
JoeBorgione
MVP Emeritus

If your address field is in the form of:

1234 S MAIN ST

Use the field calculator like this:

RIght click on your new field and select calculate, leaving the Expression Type as Python 3.  

Define a new function in the code block window:

def extractHouseNumber(inAddress):
    houseNumber = inAddress.split(' ')[0]
    return houseNumber

 

And then enter the function name and pick your address field name as the function parameter:

JoeBorgione_0-1624901154919.png

 

 

 

That should just about do it....