HOW TO
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).
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 arcpy
path = r'C:\Users\User\Test\Misc\Test.gdb\Testing'
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
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
def updateValue(value): if value == None: return '0' else: return value
updateValue(!Field_Name!)
Get help from ArcGIS experts
Download the Esri Support App