Hi,
I have some troubles calculatin with <Null> values. I have two columns and a want to cearte a third one from it. Col 1 is filled with values. Col 2 has some intentional <Null>. It want Col 3 to be conditionally filled if the value in Col2 is <Null>. Below a picture of my attempts, but it seems I do not understand python enough and I didn't find an answer.
Solved! Go to Solution.
The below should work:
def test(x, y):
if x == 'UNF_GT' and y == None:
return 'UNF_GT'
Try removing the other elif statements.
Would it be an idea to replace first the Null values with a real "0" and then do the calculations?
The below should work:
def test(x, y):
if x == 'UNF_GT' and y == None:
return 'UNF_GT'
Try removing the other elif statements.
Thank you!
A sample calculation for something unrelated.
If the second fld (fld2 or in your case 'y') is None, then split up what you want return into little bits.
If you have too many bits, you can use a dictionary to extract the value. Be wary of the output type, which in your case is text. Also provide a return value if the second field is not None
def junk_cal(fld1, fld2):
"""Account for nulls"""
if fld2 is None:
if fld1 == 1:
return "one"
elif fld1 == 2:
return "twp"
elif fld1 == 3:
return "three"
return str(fld2)