Hi community....
I need your help to create python script to calculate the value of the field that called "code" type short integer according to following condition:
def reclass(industrial_area):
if (industrial_area > two_third_neigh_area):
return 13
elif (industrial_area > one_third_neigh_area and industrial_area< two_third_neigh_area):
return 16
elif (industrial_area < one_third_neigh_area):
return unclassified
I tried to apply the above if statement but I got this message:
Solved! Go to Solution.
In the reclass() function you have defined a single variable "industrial_area", whereas you have called three variables in the code "industrial_area", "one_third_neigh_area", "two_third_neigh_area".
You should add three variables in the function, and also define the appropriate fields in the expression.
Moreover, I don't understand "unclassified"? If this is a value, it won't fit in a Short integer type. You could replace it with values like 0 or 99.
e.g.: Assuming the layer has three numeric fields viz., "industrial_area", "one_third_neigh_area", "two_third_neigh_area"
Expression:
reclass(!industrial_area!, !one_third_neigh_area!, !two_third_neigh_area!)
Code Block:
def reclass(industrial_area, one_third_neigh_area, two_third_neigh_area):
if (industrial_area > two_third_neigh_area):
return 13
elif ((industrial_area > one_third_neigh_area) and (industrial_area< two_third_neigh_area)):
return 16
elif (industrial_area < one_third_neigh_area):
return 99
The def needs to have the other field names passed to it since it has no values for them. You only pass the function 1 field name (industrial_area). And I would check ArcMap's syntax for passing field names to functions eg do they need to be enclosed in square brackets, exclamation marks like in ArcGIS Pro)
You didn't include the other fields you were comparing in the function definition.
In the reclass() function you have defined a single variable "industrial_area", whereas you have called three variables in the code "industrial_area", "one_third_neigh_area", "two_third_neigh_area".
You should add three variables in the function, and also define the appropriate fields in the expression.
Moreover, I don't understand "unclassified"? If this is a value, it won't fit in a Short integer type. You could replace it with values like 0 or 99.
e.g.: Assuming the layer has three numeric fields viz., "industrial_area", "one_third_neigh_area", "two_third_neigh_area"
Expression:
reclass(!industrial_area!, !one_third_neigh_area!, !two_third_neigh_area!)
Code Block:
def reclass(industrial_area, one_third_neigh_area, two_third_neigh_area):
if (industrial_area > two_third_neigh_area):
return 13
elif ((industrial_area > one_third_neigh_area) and (industrial_area< two_third_neigh_area)):
return 16
elif (industrial_area < one_third_neigh_area):
return 99
Thank you Sir.
I applied that and it is work perfectly.
I appreciate all replays.