I need to exclude all values that contain any letter from one of the fields. Basically only integers should be left. What code (Python/VB) do I have to put in field calculator for that?
Thanks!!!
I need to exclude all values that contain any letter from one of the fields. Basically only integers should be left. What code (Python/VB) do I have to put in field calculator for that?
Thanks!!!
Ohhhh... You failed to mention that some of the entries don't have numbers in them.
So... you have to create a text/string field instead and delete the int( ) part. Now of course, if there is no numbers in the entry, you will get back an empty string.
The question remains
The rule set will determine the format of the new field, the values it returns and the outputs it will return... especially if you want this as an automagic all encompassing solution.
If you want to simply blank out any entry in which GROUTE contains a letter then perhaps you could do this (test on a copy first!):
Since GROUTE could contain letters then it cannot be a number....
GROUTE = "" if any(b.isalpha() for b in !GROUTE!) else !GROUTE!
Ted, I exported the field calculator function to Python script and I get error now..
Do you have any idea why? Thanks again
> Error ocurred in:
File "P:\Batch\J420992\CODE\PYTHON\J420992_C1_Customers.py", line 66, in <module>
arcpy.CalculateField_management(WCSCUSTOMERCOPY, "GROUTE", " \"\" if any(b.isalpha() for b in !GROUTE!) else !GROUTE!", "PYTHON_9.3", "")
> Error Class is:
<class 'arcgisscripting.ExecuteError'>
> Available error details are:
ERROR 000539: IndentationError: unexpected indent (<expression>, line 1)
Failed to execute (CalculateField).
LOL I just got back to the office.... I only jumped in because it sounded like she only wanted to ignore those rows that had a character in it... When using python, now, I avoid nulls and put an empty/blank/unused code filter and delete in a two step process since I do not trust finding nulls yet in python.
Liana I am happy you got it worked out! That's all the matters!
Liana,
Using Python, the Codeblock (Pre-logic Script Code) would be:
def result(value): import re return "" if re.search("[a-zA-Z]", value) else value
And the calculation would be:
result( !<FIELD_NAME>! )
Be careful overwriting the same field. You can't undo it unless you start an edit session first.
Larry
I covered that here Query to have only numeric values in the field
Add a numeric field (integer)
Use the python parser and use the syntax given