I'm using the following python code to replace Null values by 0, using field calculator:
def nulls(p1): if p1 is None: return 0 else: return p1
But nothing happens, Null values stay. I'm using ArcGIS Desktop 10.0.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
I recently had to replace Null values as well, but instead of the field calculator I used a short python script including an UpdateCursor, maybe this helps you:
with arcpy.da.UpdateCursor("feature_class, ["field_with_null_values"]) as cursor: for row in cursor: if row == None: row = 0 cursor.updateRow(row) print "Processing complete" del row
the only thing I don't know is if this works for 10.0, I work with 10.2
At 10.0, which does not have the Data Access module (arcpy.da), the code using old style cursors would look more like this:
cursor = arcpy.UpdateCursor(inFeatureClass) for row in cursor: if row.getValue(inField) == None: row.setValue(inField,0) cursor.updateRow(row) del row,cursor
The underlying cause of this problem seems to be bug number NIM059424 which was present in ArcGIS Desktop 10.0 and resolved by ArcGIS 10.1 for Desktop:
Null values in the feature class do not get replaced when using Python in the Field Calculator.