Use Calcuate Field to replace values

191
1
Jump to solution
09-19-2019 08:17 AM
JohnBrand
New Contributor III

I'm trying to use the Field Calculator (python) to replace existing values (string) in Field1 with the values in Field2 (string) but only if Field2 is not Null.

Having trouble with the syntax.

Thanks,

John

0 Kudos
1 Solution

Accepted Solutions
LanceCole
MVP Regular Contributor

John,

In Field Calculator you will want to create a def statement in the code block and pass the values of Field1 and Field2 to this statement.  The Statement will look something like the following:

def checkValue(f1, f2):
  if f2 is None:
    return f1
  else:
    return f2
‍‍‍‍‍

You would call the function using:

checkValue(!field1!, !field2!)

View solution in original post

1 Reply
LanceCole
MVP Regular Contributor

John,

In Field Calculator you will want to create a def statement in the code block and pass the values of Field1 and Field2 to this statement.  The Statement will look something like the following:

def checkValue(f1, f2):
  if f2 is None:
    return f1
  else:
    return f2
‍‍‍‍‍

You would call the function using:

checkValue(!field1!, !field2!)