English

How To: Replace null values with zero in an attribute table

Summary

The instructions provided describe how to replace null values with zeros in an attribute table using the Field Calculator in ArcMap. In this example, Python code is used to replace null values in a field without having to edit every record individually.

 

Procedure

To replace null values with zeros in a field in an attribute table, follow the steps below:

  1. In ArcMap, click the Editor drop-down menu on the Editor toolbar, and select Start Editing.
  2. In the Table Of Contents, right-click the selected layer, and select Open Attribute Table.
An image of a field with null values in an attribute table.
  1. Right-click the field with null values, and click Field Calculator.
An image of selecting the field calculator of a field.
  1. In the Field Calculator, select the Python parser, and check the Show Codeblock check box.
  2. In the Pre-Logic Script Code box, copy and paste the following code:
def updateValue(value):
  if value == None:
   return '0'
  else: return value
  1. Type the following code in the second box, and replace '!Field_Name!' with the field name from the Fields list, as shown in the image below.
updateValue(!Field_Name!)

An image of calculating null values in the Field Calculator.
  1. Click OK, and the null values are replaced with zeros in the field, as shown in the image below.
An image of null field values replaced with zero.
  1. In the Editor toolbar, click Stop Editing and Save Edits to keep the changes.

Related Information