[GIS] How To Determine Percent of Matched Data

arcgis-desktopfield-calculatorpython

In my attribute table, I have 2 columns with qualitative (categorical) data. Both of them are from different sources so I am trying to find the percent of matched data from these 2 columns. I created a new column labeled 'Matched', and wrote the following codeblock in the Field Calculator to determine the values, but I am getting an error on line 2-3. Do I have to convert them to string using str()?

def matchedRecords(x):
    x = (column.name)
    x2 = (column2.name)

    if x == x2:
        resultIs = "Matched"
    else:
        resultIs = "Unmatched"
    return resultIs

And then matchedRecords(!Matched!) in the second area of the Field Calculator. I want to determine the total matched values versus unmatched values to find the percentage. Is this the best way to do it? Thanks.

Best Answer

I think the logic is incorrect for what you are trying to accomplish. I believe you need to pass the first two columns in the function:

def matchedRecords(A, B):
    if A == B:
        results = "Matched"
    else:
        results = "Unmatched"
    return results

Then in the field calculator for the Matched field:

matchedRecords(!column1!, !column2!)

This is untested, but should work. Once you have the number (count) of matched vs unmatched, you can calculate a percentage.