I am looking for the Python function that will allow me to convert a field from a string to a integer in a new field. I do not want to write Python script. It appears that the proper Python function would be .int but it doesn't exist in my field calculator in ArcGIS 10. Please help!
Solved! Go to Solution.
You can use int(!FieldName!) in the field calculator is the parser is set to Python
You can use int(!FieldName!) in the field calculator is the parser is set to Python
or
>>> s = ["1" ,"2", "", "abc"]
>>> [int(i) if i and i.isdigit() else -9999 for i in s]
[1, 2, -9999, -9999]
>>>
can you test
[int(i) if i and i.isdigit() else -9999 for i in !FieldName!][0] or
( int(i) if i and i.isdigit() else -9999 for i in !FieldName! )
no arc* to text
Pamela,
In case you run into parser errors with Xander's answer, try it like so:
So the INT function does not exist in 10.3 Enterprise edition. However, I have finally found that if you open the Field Calculator and double click the string field that you want to convert, then press string. If your new field is set to Integer, it will automatically convert. Thanks for the help!
Python is case sensitive. Did you try "int" instead of "INT"?