Select to view content in your preferred language

Field Calculator Python Syntx (combining floating point and string)

800
3
10-03-2013 04:56 AM
Mtclimber03
Regular Contributor
I'm not familiar with python and I have a basic question about simple field calculations in python rather than VB. This is needed because I have a model I am exporting to python for task scheduler. My model runs fine in ArcMap but when I run it as a python script it cannot complete the field calculation in VB expression form. Any help converting the following to a python expression would be appreciated

VB Expression to convert (field is stored as float):

[Prev_Total] & " boxes collected"

--------------------------------------
This is to be calculated in a string field.
Tags (2)
0 Kudos
3 Replies
RichardFairhurst
MVP Alum
I'm not familiar with python and I have a basic question about simple field calculations in python rather than VB. This is needed because I have a model I am exporting to python for task scheduler. My model runs fine in ArcMap but when I run it as a python script it cannot complete the field calculation in VB expression form. Any help converting the following to a python expression would be appreciated

VB Expression to convert (field is stored as float):

[Prev_Total] & " boxes collected"

--------------------------------------
This is to be calculated in a string field.


Python would be:

str(!Prev_Total!) + " boxes collected"
0 Kudos
Mtclimber03
Regular Contributor
Ok this worked but with one issue. When the field was calculated it pulled over a decimal place that was not happening in VB. For example I am seeing

1678.0 boxes collected

Is there a way to have the expression in python use zero decimals? i.e I am looking for the result of

1678 boxes collected

or better yet

1,678 boxes collected
0 Kudos
RichardFairhurst
MVP Alum
To make a comma delimited number with no decimal places do this in a Python calculation:

'{0:,.0f}'.format(Prev_Total) + ' boxes collected'
0 Kudos