Select to view content in your preferred language

Error when doing basic calculate field command: ArcGISPro

2397
2
04-22-2018 06:37 PM
MasonGrant
New Contributor

I get this error when trying to calculate a field:

ERROR 000539: Error running expression: u"5359" / 5312094.0
Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'str' and 'float'
Failed to execute (CalculateField).

I downloaded census tracts for a county in Ohio, then I joined thiswith population data from American Fact Finder. After I export the data I joined, I add a new field "Pop Density"... To calculate this new field I need to divide Total population "HD01_S001" with the area of the Census tract "ALAND".. When I put this expression in the calculate field command I get the error above.. Don't understand what could be going wrong here...

Tags (1)
0 Kudos
2 Replies
TiffanyRufo
Frequent Contributor

Hello! By my best understanding the  division is not working because the field types are not the same. Somehow you need to get the population density from a string to a float.

I don't know of an elegant way to do this, you could brute force it by creating a new field make the type double and run a quick calculation so that the new field equals the values of "HD01_S001". After that is done you should be able to do your original calculation with the new field substituting for the population density field.

Hope someone has a more finessed solution for you!

0 Kudos
BeckyGerlach
Emerging Contributor

For Python you should be able to

float(!HD01_S001!)/float(!ALAND!)