I was wondering what's the fastest method to compare similarity between two lists of strings (e.g. two dataframes, documents etc.) using levenshtein distance or other procedures.
I am currently using:
def wuzzyfuzzy(df1, df2):
myList = []
total = len(df1)
for idx1, df1_str in enumerate(df1.col1):
myDict = {}
my_str = ('Progress : ' + str(round((idx1/total)*100,3))+'%')
sys.stdout.write('\r' + str(my_str))
sys.stdout.flush()
for idx2, df2_str in enumerate(df2.col1):
s = SequenceMatcher(None, df1_str, df2_str)
r = s.ratio()
myDict.update({df2_str:r})
best_match = max(myDict, key=myDict.get)
myList.append([df1_str, best_match, myDict[best_match]])
return myList
As the dataframes that are passed to the function have both > 30.000 values, it takes currently around 6 hours to compare each value in df1 with all other values in df2 to find the best match.
Of course I cleaned the strings as good as possible beforehand (all lowercase, get rid of punctuations etc.)
What's the most efficient way to perfom such task?