1

Just wondering if there's an easy way to fill null values in one column in an attribute table with values in another column of the same attribute table by just writing a query "just the "null values" to be filled with details I already have in another column".Found this query field 1= sec volt, field 2: Lv connection

def updateValue( !SecVolt!, !LVConnection! ): 
if !SecVolt! is None: return !LVConnection! 
else: return '0'

but in my case I don't want to replace the value with "0" but with values in another column.

1
  • Yes I can use field calculator but the query seem not to be working!
    – Bob
    Commented Sep 6, 2019 at 13:13

2 Answers 2

4

All geoprocessing tools honour selections. So simply select the rows where column 1 has the NULL values then run a field calculate and select the field you want the values to come from. As you have a selection only those rows will be updated. Absolutely no code required.

1
  • +1 because this applies to scores of similar questions. Minimize use of coding is also right, too much bias lately.
    – FelixIP
    Commented Sep 6, 2019 at 21:08
2

With python parser try:

Code block:

def updateValue(field1, field2):
    if field1 is None:
        return field2
    else:
        return '0'

Call with:

realfieldname1=

updateValue(!realfieldname1!,!realfieldname2!)

When you call the function you must use the real fieldname enclosed in !!

3
  • Tried doing it this way still didn't work. here is what i tried: field 1= sec volt, field 2: Lv connection <def updateValue( !SecVolt!, !LVConnection! ): if !SecVolt! is None: return !LVConnection! else: return '0'>
    – Bob
    Commented Sep 6, 2019 at 13:51
  • Edit your question and add the code you try with. Are you sure the field you are calculating is string/text type? Otherwise return '0' should be return 0
    – Bera
    Commented Sep 6, 2019 at 14:05
  • Thanks for your response, that might be the issue why i'm getting error response. one is a "string type" and one is a "long type" and the other table was brought in through a join relationship....so I'm trying to just bring it in without any join relationship to see if it works.
    – Bob
    Commented Sep 6, 2019 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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