I'm trying to run a field calculator statement to fill an integer field based on a preceding text field - so depending on what the text is, a certain number will be assigned to it. However, the field calculator statement I'm using only seems to work if the text has no spaces in it... any help with this would be greatly appreciated!
The expression is:
And the code black is:
if Typology is "Allotments":
elif Typology is "Amenity Green Space":
elif Typology is "Park and Recreation Ground":
However, in the example above, only allotments will be assigned the requested number. If I removed the spaces from the other text, the calculation works but this isn't acceptable for what I need.
Many thanks in advance.
NOTE: You Cannot input decimal numbers in Integer Fields. You need to create a field of Double/Float Datatype to input decimal numbers.
I used the geoprocessing tool Calculate Field—Help | ArcGIS for Desktop
I used .strip() function to remove the leading and trailing spaces.
def Reclass(parcel): parcel = parcel.strip() if (parcel == 'Allotments'): x=0.3 elif (parcel == 'Amenity Green Space'): x=0.4 elif (parcel == 'Park and Recreation Ground'): x=1.65 return x
Not to get hung up on semantics, although I always do anyways, but you can input decimal numbers into integer fields using the field calculator. That said, you should not because it converts the decimal to an integer and some of the information is lost. But then again, maybe converting/casting the type is fine or desirable in some circumstances. Oddly, I always thought the field calculator would just truncate a decimal, but a quick test shows it rounds.