So I have several field in an attribute table that have <Null> value, I am wanting to using the 'Calculate Field' GP tool to select the <Null> values and replace them with zero. Anyone have any ideas on the Python and/or SQL statement I would use to execute this?
The sql statement you'll use in the selection :
<YourField> is null
Your field calculator will then look like this:
I am trying to do all of this in one step either using the 'Calculate Field' GP in Pro or even better the 'Calculate Fields' GP tool in Pro. Any idea how that would look?
Using the tools? No. Using a python script, absolutely. What's your preference?
Would this work for your purposes Chad? Just replace with your field name NRCS_Score or whatever in place of what I have specified for my field CENTERLINEID. This will write Zero to all NULL values:
Result of CENTERLINEID field from <NULL> to 0:
>
EDIT: Here is the code using your NRCS_Score field as example:
NRCS_Score =
updateValue(!NRCS_Score!)
Code Block:
def updateValue(value):
if value == None:
return '0'
else: return value
PEP 8 -- Style Guide for Python Code
For reference
if foo is None:
'is' is preferred to '==' as a general recommendation
The following field calculator Python expression (no Code Block necessary) should work for you:
0 if !field! is None else !field!