1

How do you update NULL values within a geodatabase table using the ArcGIS Field Calculator (service pack 4) without changing other values to NULL? I've tried the suggestions on this previous question:

How do you test for a NULL string field in the Field Calculator with Python?

When I run the script it changes everything to NULL.

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

RemoveNULL(str(!myxField!))

e.g.

before running script

1
23
NULL
5

after running script

NULL
NULL
NULL
NULL

Can you not use python script on mdb table?

2

You logic is wrong. The way it reads now, if not null, then put 0. That explains why null is now set to zero. Because if not null, so it it is null then it equals 0.

Can you post more of the code?

  • Sorry I put the wrong statment, I updated my question. – artwork21 Jul 9 '12 at 16:26
  • You statement still reads, that is x is none (null), then set to 0. Change the 0 value to something else to see what happens. – Jamie Jul 9 '12 at 16:50
  • 1
    Also add an else statement for what to do if it is not null. – Jamie Jul 9 '12 at 16:51
0

Ok, thanks to Jamie here is the working solution:

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

RemoveNULL(str(!myxField!))
  • 1
    why is it str(!myxField!)? that would make the nulls into '' which is no longer None. It should be RemoveNULL(!myxField!) – Michael Stimson Jul 2 '15 at 3:40
0

Just for fun, I noticed ESRI 10.3 only shows NULL as 0 so you have no idea what is in there. In QuantumGIS Brighton or later, the field shows as NULL, but you don't know which one. I modified this as the following (I added a zero after copying off Jamie):

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

RemoveNULL(str(!myxField!))

If you have a NULL with any other weird value just add more else if with return values to cover those scenarios.

P.S. Thank you Jamie :)

Now, does anyone know how to make this script change NULL to zero for all columns that do not already have a number?

-Prometheus

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.