Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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?

share|improve this answer
    
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

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!))
share|improve this answer
1  
why is it str(!myxField!)? that would make the nulls into '' which is no longer None. It should be RemoveNULL(!myxField!) –  Michael Miles-Stimson 2 days ago

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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