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.
-
you can create a simple selection "Field a" = "Field b" > calculate your "fields c" to 0 then reverse selection, calcutate "fields c" to 1GeoStoneMarten– GeoStoneMarten2015年12月08日 19:41:10 +00:00Commented Dec 8, 2015 at 19:41
-
if you want just not equal value, select "Field a" <> "Field b"GeoStoneMarten– GeoStoneMarten2015年12月08日 19:42:37 +00:00Commented Dec 8, 2015 at 19:42
3 Answers 3
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.
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
-
1Didn't even use the code block. I love it! This saved me.Cradle2theGabe– Cradle2theGabe2019年02月15日 00:21:03 +00:00Commented Feb 15, 2019 at 0:21
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!)
Explore related questions
See similar questions with these tags.