I am new to scripting and am trying to figure out how to write an If-then statement to populate a field in field calculator. I want to basically say if a certain field has a NULL value in it, then the result is "No" in that field. If the certain field has a value in it, then I want the result to be "Yes".
Solved! Go to Solution.
Thank you everyone for your help! I was able to accomplish what I wanted by doing a selection query and field calculating on the results.
Not sure it's possible; my work around has always been to create a selection and calc your value.
select: 'TheField' is null
It would be something like this.
Expression:
Reclass(!FieldwithNullValuesHere!)
Expression Type:
Python_9.3
Code Block:
def Reclass(field):
if field == "None":
return "No"
else:
return "Yes"
This is assuming your field is actually <Null>, not blank, or something else:
Codeblock:
def blah(field): if field: return "Yes" else: return "No"
expression:
blah(!yourfield!)
See the following Esri Documentation and look for the section titled "Using Code Blocks"
Calculate Field Examples
http://desktop.arcgis.com/en/desktop/latest/manage-data/tables/calculate-field-examples.htm
Thank you everyone for your help! I was able to accomplish what I wanted by doing a selection query and field calculating on the results.