[GIS] ArcMap Field Calculator Remove Null values

arcgis-desktoparcmapfield-calculatornullpython-parser

I would like to remove the NULL/empty values from a table that is stored in a Geodatabase. Last time I tried doing so it worked fine, today I have some issues with the codes (Double Field). I have used the following python sequence;

Pre-logic:

def RemoveNULL(x):
  if x is None:
    return '0'
  elif x == ' ':
    return '0'
  else: return x

Second Field:

    RemoveNULL(!Field_name!)

According to my opinion the code is correct but the Geoprocessing window illustrates a failure each time I calculate just after 1-3 seconds.

Best Answer

Im sure this is Python and not VB script. By putting the 0 in speech marks, you are trying to say that 0 is a string, when its not. As added by Martin, please select the Python Parser instead of the VB Script Parser. Try and use the following code:

def RemoveNULL(x):
  if x is None:
    return 0
  elif x == ' ':
    return 0
  else: 
    return x
Related Question