pythonarcgisarcmap

How to slice off last two characters in a string then convert to a double?


I'm trying to do a field calculation in ArcMap from one field to another. I need to slice off the last two characters of one field, and convert to float (or double).

I'm trying to do this:

float(!StatedArea![-2])

My starting values (from the StatedArea field) are like this:
12.99 a
0.2377 a
0.0041 a

I just want to take off the space and the "a".

All I'm getting is ERROR 000539, with this message "ValueError: could not convert string to float"

Any ideas what the issue could be?


Solution

  • float(!StatedArea![:-2])
    

    should work. You might want to revisit list indexing in python: https://www.tutorialspoint.com/python/python_lists.htm