4

Using 10.2.2 I am attempting to compare two fields in an attribute table using the Field Calculator. I'd like to return a value of '0' if they are equal and a value of '1' if they are not equal.

There are 600,000 records to compare and the overwhelming majority will end up being equal. So, in essence this is an exercise to identify the minority that are not equal.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 8, 2015 at 18:10
2
  • you can create a simple selection "Field a" = "Field b" > calculate your "fields c" to 0 then reverse selection, calcutate "fields c" to 1 Commented Dec 8, 2015 at 19:41
  • if you want just not equal value, select "Field a" <> "Field b" Commented Dec 8, 2015 at 19:42

3 Answers 3

4

You can use this line in "Select by Attributes" Field1 <> Field2. This will select all where they are not equal, then field calculate a 1 into a column.

answered Dec 8, 2015 at 18:20
0
4

You can use a one liner code as follows: 1 if !field1! == !field2! else 0 Do not forget to select the 'python' radio button as opposed to the 'VB' in the field calculator

answered Dec 8, 2015 at 18:22
1
  • 1
    Didn't even use the code block. I love it! This saved me. Commented Feb 15, 2019 at 0:21
3

You could define a function in python/vb. Check 'Show Codeblock' and a script similar to the one below could be used. In the pre-logic Script code, type:

def check(field1, field2):
 if field1==field2:
 return 0
 else:
 return 1

And in the new field, type in:

NEW FIELD=

 check(!yourfield1!, !yourfield2!)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Dec 8, 2015 at 18:22
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.