I am looking for the integer conversion of a string field in Python functions for the field calculator.

3108
5
Jump to solution
02-15-2016 07:23 AM
PamelaCaskie
New Contributor

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!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

You can use int(!FieldName!) in the field calculator is the parser is set to Python

View solution in original post

5 Replies
XanderBakker
Esri Esteemed Contributor

You can use int(!FieldName!) in the field calculator is the parser is set to Python

DanPatterson_Retired
MVP Emeritus

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

ChrisSmith7
Frequent Contributor

Pamela,

In case you run into parser errors with Xander's answer, try it like so:

PamelaCaskie
New Contributor

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!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Python is case sensitive. Did you try "int" instead of "INT"?

0 Kudos