How do to fuzzy matching on excel file using Pandas?
<p>I have a table called account with two columns - ID &amp; NAME. ID is a hash which is unique but NAME is a string which might have duplicates.</p>

<p>I'm trying to write a python script to read this excel file and match 0-3 similar NAME values, but I just cannot seem to get it to work. 
Could someone help out? Thanks</p>

<pre><code>import pandas as pd
from fuzzywuzzy import fuzz
import difflib

def get_spr(row):
    d = name1.apply(lambda x: (fuzz.ratio(x['NAME'], row['NAME']) * 0 if row['ID'] == x['ID'] else 1), axis=1)
    d = d[d&gt;= 60]
    if len(d) == 0:
        v = ['']*2
    else:
        v = name1.ix[d.idxmax(),['ID' , 'NAME']].values
    return pd.Series(v, index=['ID', 'NAME'])


def score(tablerow):
    d = name1.apply(lambda x: fuzz.ratio(x['NAME'],tablerow['NAME']) * (0 if x['ID']==tablerow['ID'] else 1), axis=1)
    d = d[d&gt;90]
    if len(d) == 0:
        v = [''] * 2
    else:
        v = name1.ix[d.order(ascending=False).head(3).index, ['ID' , 'NAME']].values
    return pd.DataFrame(v, index=['ID', 'NAME'])

account = "account_test.xlsx"

xl_acc1 = pd.ExcelFile(account)
xl_acc2 = pd.ExcelFile(account)

acc1 = xl_acc1.parse(xl_acc1.sheet_names[0])
acc2 = xl_acc2.parse(xl_acc2.sheet_names[0])

name1 = acc1[pd.notnull(acc1['NAME'])]
name2 = acc2[pd.notnull(acc2['NAME'])]
print 'Doing Fuzzy Matching'


name2= pd.concat((name2,name2.apply(get_spr, axis=1)), axis=1)
name2.to_excel(pd.ExcelWriter('res.xlsx'),'acc')
</code></pre>

<p>Any help would be much appreciated!</p>

<p>The file has rows like this:-</p>

<pre><code>ID                    NAME
0016F00001c7GDZQA2  Daniela Abriani
0016F00001c7GPnQAM  Daniel Abriani
0016F00001c7JRrQAM  Nisha Well
0016F00001c7Jv8QAE  Katherine
0016F00001c7cXiQAI  Katerine
0016F00001c7dA3QAI  Katherin
0016F00001c7kHyQAI  Nursing and Midwifery Council Research Office
0016F00001c8G8OQAU  Nisa Well
</code></pre>

<p>Expected (output dataframe) would be something like:</p>

<pre><code>      ID               NAME          ID2          NAME2
    &lt;hash1&gt;          katherine      &lt;hash2&gt;       katerine
    &lt;hash1&gt;          katherine      &lt;hash3&gt;       katherin
    &lt;hash4&gt;          Nisa Well      &lt;hash5&gt;       Nisha Well
</code></pre>

<p>Issue: The above code just reproduces the input as the output saved file without actually concatenating any matches. </p>