Convert numbers in a text field to an integer field

5921
4
09-16-2016 10:45 AM
MargoBerendsen
New Contributor

I have a text field with temperatures in it (mostly numbers, but some with "unknown temperature") that I want to calculate to an integer field so I can create symbols using a quantitative classification. 

In ArcGIS I could  calculate using [TempF].asNumber  but I can't find a similar function in ArcPro. 

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

If you text field only contains integers, as text, or a text value, you can use !yourfield!.isdigit() using a python parser.  If your field contains floating point values as text or a text value, then there is more work to do.

>>> a
'1'
>>> b
'1.1'
>>> a.isdigit()
True
>>> b.isdigit()
False
>>> b.isalnum()
False

so before giving a code block to cover the cases for floating point values, values in scientific notation, NaNs and complex, see if you have just integers (as text) or text

MargoBerendsen
New Contributor

I see how this tests to see if the text value is integer, but how do I change it to integer? Thank you!

0 Kudos
DanPatterson_Retired
MVP Emeritus

in the field calculator, python parser

int(!Your_Fieldname_here!)  # note the ! before and after the field name

>>> a = '1234'
>>> int(a)
1234
DanPatterson_Retired
MVP Emeritus

You may wish to move this thread to https://community.esri.com/community/gis/applications/arcgis-pro?sr=search&searchId=9ac689ca-14f7-45...‌ to get a wider audience, you have published in a group with limited membership