# Using Python in Field Calculator to compare two fields

I'm trying to use field calculator to compare two fields in a table of tax parcel data, Land Value (LAND_VAL) and Improvement Value (IMPRVT_VAL). My goal is to determine (1) Parcels with land value less than the value of improvements, (2)Land value about the same value as improvements, (3) Land value more than improvement value, but less than twice the value, and (4) Land value which is more than twice improvement value.

I wrote the following script, and it runs successfully in Field Calculator (doesn't give any errors), but it only returns 4, which is clearly not the case in the data.

``````LV = " !LAND_VAL! "
IV = " !IMPRVT_VAL! "

def Recode(Val_Analys):
if LV < IV:
return 1
elif LV == IV:
return 2
elif (LV > IV and LV < (IV * 2)):
return 3
elif LV > (IV * 2) :
return 4
else:
return 0

Recode(!Val_Analys!)
``````

Any help would be much appreciated.

-

Just put this as the script code:

``````def Recode(LV, IV):
if LV < IV:
return 1
elif LV == IV:
return 2
elif (LV > IV and LV < (IV * 2)):
return 3
elif LV > (IV * 2) :
return 4
else:
return 0

Recode(!LAND_VAL!, !IMPRVT_VAL!)
``````
-
Thank you! I need to practice python a bit more obviously. – Chris Apr 9 '14 at 23:08
You're welcome. Easy mistake. – ianbroad Apr 9 '14 at 23:12