How To: Replace null values with zeroes in an attribute table in ArcMap
Summary
An attribute table may contain multiple fields with null values and by default, these fields are populated with an empty space. In some cases, some tools or functions do not execute if the fields are not populated with characters (non-nullable fields).
Procedure
This article describes two ways to replace null values in an attribute table; by replacing the null values in the attribute table, or by replacing the null values in a single column (field).
Replace the null values in an attribute table using the ArcPy module
Note: The following script can be used in the Python console of ArcMap, or as a stand-alone script.
- Import the necessary module.
import arcpy
- Specify the path to the feature class.
path = r'C:\Users\User\Test\Misc\Test.gdb\Testing'
- List all the fields, and create an empty array to store all the field values.
fieldObs = arcpy.ListFields(path) fieldNames = []
- Loop through the fields, and determine the count for the values.
for field in fieldObs: fieldNames.append(field.name) del fieldObs fieldCount = len(fieldNames)
- Create a new loop to find and replace the null fields with the desired value using the UpdateCursor() function.
with arcpy.da.UpdateCursor(path, fieldNames) as curU: for row in curU: rowU = row for field in range(fieldCount): if rowU[field] == None: rowU[field] = "0" curU.updateRow(rowU)
- Delete the created cursor to release the lock on the feature class.
del curU
The following shows the full script:
import arcpy path = r'C:\Users\User\Desktop\Misc\Piracy.gdb\Continents' fieldObs = arcpy.ListFields(path) fieldNames = [] for field in fieldObs: fieldNames.append(field.name) del fieldObs fieldCount = len(fieldNames) with arcpy.da.UpdateCursor(path, fieldNames) as curU: for row in curU: rowU = row for field in range(fieldCount): if rowU[field] == None: rowU[field] = "0" curU.updateRow(rowU) del curU
Replace the null values in a single field using the Field Calculator and Python parser
- In ArcMap, click the Editor drop-down menu on the Editor toolbar, and select Start Editing.
- In the Table Of Contents, right-click the selected layer, and select Open Attribute Table.

- Right-click the field with null values, and select Field Calculator.

- In Field Calculator, select the Python parser, and check the Show Codeblock check box.
- In the Pre-Logic Script Code box, copy and paste the following code:
def updateValue(value): if value == None: return '0' else: return value
- 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!)

- Click OK, and the null values are replaced with zeros in the field, as shown in the image below.

- On the Editor toolbar, click Stop Editing and Save Edits to keep the changes.
Related Information
- ArcMap: Fundamentals of field calculations
- ArcMap: Calculate Field examples
- ArcMap: Making simple field calculations
- How To: Calculate fields where some inputs are null values
- FAQ: How do you represent NULL values when converting from a geodatabase, or shapefile, to a coverage?
- How To: Replace null values with zeroes in an attribute table in ArcGIS Pro
Last Published: 5/26/2020
Article ID: 000016100