Select to view content in your preferred language

I am trying to assign values to a new field (1 or 0), based on whether there are particular attributes present in another field, in the same table.

477
2
09-10-2019 05:39 PM
Christopher_Douglas
New Contributor

I have an attribute table for a shape file, that has the attributes for a number of polygons. I have created a new field, that I need to have values of 1 or 0, based on whether there are attributes present in a different field. This is all being conducted within the same attribute table. 

0 Kudos
2 Replies
LanceCole
MVP Regular Contributor

Christopher,

You can easily do this using Field Calculator and a little python code.  Assuming you are using ArcGIS Desktop 10.x, please take a look at Calculate Field examples—Help | ArcGIS Desktop.

You would create a function such as below using def statement in the call block then call the function.  This example checks for None or Null values and returns 0 if found or 1 if not.  This can be customized to meet your needs or to address empty strings or specific values.

def checkAttrib(field1):
  if field1: #this will return "0" for None or Null values or "1" for most other values
    return 1
  else:
    return 0‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The function is called using:

checkAttrib(!Field_Name_to_Check!)

The code can be further expanded to check multiple fields and return different values. You can modify the if statement to check for a specific value or if the value is in a list.

if field1 == "abc":

or

if field1 in ['abc', 'xyz']:

KoryKramer
Esri Community Moderator

Or if you're using ArcGIS Pro, note that there is a Helper called Reclassify which would give you a template that you can modify: