2

I have a table (inside a File Geodatabase) that looks like this:

enter image description here

I need the values of Owner attribute to be automatically filled with the previous non-Null value. As Such:

enter image description here

Is there a Python script, usable in Field Calculator, that can achieve this?

2 Answers 2

6

You can do this directly within the CalculateField tool; use the following code block:

prevval = None

def calcowner(ownerval):
    global prevval
    val = prevval if ownerval is None else ownerval
    prevval = val
    return val

And the expression:

calcowner(!Owner!)

Note that this probably won't work in ArcGIS 10.0 due to a bug that was fixed in 10.1, but 10.1+ should be good:

NIM059424 - Null values in the feature class do not get replaced when using Python in the Field Calculator.

1

This can be done with a custom python parser function like:

Here we evaluate if value is NULL or not, if not write value to text file, if NULL pull value from text file:

def update(val):
  if val:
    f = open('C:/Temp/temp.txt','w')
    f.write(val)
    f.close()
    return val
  else:
     f = open('C:/Temp/temp.txt','r')
     for v in f:
         return v
     f.close()

And add the function call in the text box below the pre logic one:

update(!theFieldName!)

Your Answer

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

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