[GIS] ArcGIS field calculator: Calculating a new field using multiple fields with python

arcgis-desktoparcmapfield-calculatorpython

Basically, I have a large polygon data set that has soil data for an area and I want to assign numeric values to the data based on soil texture text values (e.g. SIL=4, CLY=7, …). However, the soil texture is divided into three different columns:
1) TEXTURE1;
2) TEXTURE2; and,
3) TEXTURE3.
Usually TEXTURE1 gives me the data I need to assign the numeric value in a new field, but in some cases the value for TEXTURE1 is listed as N/A, and I need to use the text from TEXTURE2 to assign the number. Is it possible to write a script where if the text from the TEXTURE1 field is NOT N/A return TEXTURE1, else return TEXTURE2?
The new field would be a text field.

Best Answer

Perhaps something like this?

Code block:

def GetTexture(Text1,Text2):
  if Text1 is None:
    return Text2
  else:
    return Text1

With expression NEWTEXTURE = GetTexture(!TEXTURE1!, !TEXTURE2!)

Related Question