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!
Solved! Go to Solution.
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
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
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: