2

I am trying to field calculate a double field (PID) to a new string field (PIN). Using:

qry = '"139-{}".format(!PID!)'
arcpy.CalculateField_management(out, "PIN", qry, "PYTHON")

Given a PID = 260360160 The output generated in string PIN field is:

PIN = 139-260360160.0

How can I get rid of the .0? I assume this is carry over from the original field being a double.

I am running ArcGIS 10.2 and Python 2.7.3

3

You can use the built-in int() function of python to convert what appears to be a float value in the PID field to an integer:

qry = '"139-{}".format(int(!PID!))'

This should return PIN = 139-260360160

You could also do this by specifying zero decimal places in your string formatting function:

qry = '"139-{:.0f}".format(!PID!)'

Eight Bits Equals a Byte has a really useful page on string formatting in python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.