I have two fields that contain addresses that I am trying to compare by making sure just the numbers match because the addresses in one of those fields are not standardized. I already have one field that contains the numbers for the addresses that are standardized so now I am trying to create a field for numbers for the non-standardized addresses. I need to extract the numbers from the other field so I can find the ones that do not match. I am trying to use this script:
int(''.join([i for i in !YourFieldName! if i.isdigit()]))
But I get an error processing popup. I am new to using python so I was hoping someone might be able to point me in the right direction. Thanks!
Hey @EGardner7
Could you attach a picture of the error? It may be because something is null or does not show up correctly.
You could also try placing a function in the code block and calling it for your attribute selection:
def extract_numbers(field):
numbers = ''.join([i for i in field if i.isdigit()])
return int(numbers) if numbers else None
extract_numbers(!YourFieldName!)
This would return None if numbers is not present.
Cody
Hi Cody thanks for your response. Here is the error message.
Hey @EGardner7
It may be how you are returning the function, I believe you are trying to return an integer, is the AncillaryRole field an integer field? If it is not, you may try changing the datatype to be a string or similar using the string function str(), you may not even need to use str() as it could be returning as a string already:
def extract_numbers(field):
numbers = ''.join([i for i in field if i.isdigit()])
return str(numbers) if numbers else None
extract_numbers(!YourFieldName!)
Cody
Hey Cody I got a different error message this time.
Hey @EGardner7
Looking at the program, I believe this cannot take a function as I originally stated, how about this here:
str(''.join([i for i in !YourFieldName! if i.isdigit()])) if ''.join([i for i in !YourFieldName! if i.isdigit()]) else None
I'm not as versed in ArcMap and don't have access either, so if this doesn't end up working, I'm grasping for straws.
Cody
Hi Cody this script finished loading but it did not return anything. Do you happen to know what might have gone wrong? Really appreciate all of your help with this
Hey @EGardner7
I was able to speak with someone nearby and get access to their ArcMap to check some things, are you entering the function like this here?
I believe the function will need to be in the pre-logic script code, and the extract_numbers in the assignment. Could you send a picture of this setup on your side?
Cody