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!
You can use int(!FieldName!) in the field calculator is the parser is set to Python
Pamela,
In case you run into parser errors with Xander's answer, try it like so:
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
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"?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.