4

I am having some difficulties to change "NULL" values to zero in geodatabase. I have tried the following python code in ArcGIS 10.1 ("Field Calculator") to change it but did not work.

Pre-Logic Script Code:

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

Calculation field:

RemoveNULL(str( !DEAD_VOL_PER_HA_SPP1_125!))

Error message:

ERROR: 999999: Error executing function
The value type is incompatible with the field type. [dead_pine]
Failed to execute (calculate field)
2

2 Answers 2

9

I can see from your field name !DEAD_VOL_PER_HA_SPP1_125! that the field you are calculating is likely a float or integer type field. Assuming this is true, you cannot write a space or '' into a number-based field (e.g. return ''). Valid values for number-based fields include None or a numeric value.

You will need to either create a new text field to store the special character (i.e. a space) or change the return output to an integer or float.

The following works for both text and numeric fields (Python Parser):

def replaceNull(x):
  if x is None:
    return 0
  else:
    return x

replaceNull(!YourFieldName!)
7
  • Hi Aaron, Thank you very much for your response and suggestion. I have tried your suggestion but did not work. I have change the space in the return field and calculate it no changes. I have also tried to create a new text field and calculated but did not change the null value but it calculated something but it does appear in the field column. Could you please give me bit more in detail about this matter. I am new in GIS field. Thanks is advance for your help Oct 9, 2014 at 17:23
  • @Amalesh Dhar No problem, is the field a integer or float field, or a text field? What value would you ideally like to change None type values to?
    – Aaron
    Oct 9, 2014 at 17:35
  • Thanks, I have tried both float and text with newly created field. After that tried to change "null/none to zero. But did not work Oct 9, 2014 at 17:49
  • @AmaleshDhar Is your only goal to replace Null values with 0? Your script would indicate otherwise...
    – Aaron
    Oct 9, 2014 at 21:21
  • 1
    Hi Aaron,Thank you very much for your help. Its working. Really I am very much appreciating your help. Oct 9, 2014 at 22:34
3

Create a new field and put field type is text after that you should use field calculator the value by simply select all "nulls" and change it in to "0".

3
  • Hi Singh, Thank you very much for your helping hand. I have done it but did not change NULL to zero. But it calculated something and there is no error message. I don't know what happened to calculation? Oct 9, 2014 at 17:25
  • when you run field calculator over "NULL" Value then you should put value "O", because of this is Text type field so need some value. Hope so you will done if you find again problem then frankly you must tell me.
    – Singh
    Oct 10, 2014 at 4:48
  • Hi Singh, I have found the solution with the help of Aaron. Thank you very much for your helping hand. Oct 16, 2014 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.