Isdigit code for addresses

946
5
08-07-2017 11:15 AM
EmmanuelJohn1
New Contributor

Hello everyone,

   What would be the field calculator script code to only extract the numbers and nothing else from the fieldname column to hnum column?

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus
a = '12ab34cd5'
b = int("".join([i for i in a if i.isnumeric()]))
# in field calculator
# python parser of course
int("".join([i for i in !YourFieldNameHere! if i.isnumeric()]))‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
EmmanuelJohn1
New Contributor

Thankyou Dan

0 Kudos
DanPatterson_Retired
MVP Emeritus

no problem Emmanuel

0 Kudos
JoeBorgione
MVP Emeritus

Here is a thread I started some time ago:  https://community.esri.com/thread/163731 It might give some insight to using Python to parse out address components.

Something I noticed in your sample data and it's quite common with address data, and that is the lack of consistency. Your third record has no house number; I realize it's probably a dummy record but those kinds of inconsistencies need to be handled or your parser will error out once it hits a line like that.  So either make sure your data is clean, or trap errors in your script.

That should just about do it....
0 Kudos
EmmanuelJohn1
New Contributor

Joe ,

   Yes, you are correct. There can also be other values that are completely blank which can cause further issues. But for what i was trying to do it was helpful to get an idea for where to start.

Dan's code was helpful for the start, which helped me make labels from Label Expression Window instead of having to maintain a new field. This was mainly for Home Number Label service.

 int("".join((i for i in [YourField] if i.isnumeric())))

This expression neglects all the blank values, and the fields without the numbers in them.

0 Kudos