title: Applying a function many-to-many using pandas
body: <p>I'm using <code>pandas</code> to do some conditional filtering based on string matching using the <code>fuzzywuzzy</code> module. I've written some code that works, but is painfully slow and goes against every instinct in my body because I'm using a for loop over a pandas Series.</p>
  
  <p>My issue is that I want to compare array of strings to another, and if a string in one array is similar enough to ANY string in the other array, I want to remove it from the array completely. My current code is this:</p>
  
  <pre><code>from fuzzywuzzy import fuzz
  import pandas as pd
  for value in new_contacts['StringMatch']: # this is a pandas column in a dataframe
      previous_contacts['ratio'] = previous_contacts['StringMatch'].apply(lambda x: fuzz.ratio(x, value))
      previous_contacts = previous_contacts[previous_contacts['ratio'] &gt; 97] # fuzz.ratio outputs an int between 0 and 100
      previous_contacts.drop('ratio', axis=1, inplace=True)
  </code></pre>
  
  <p>Does anyone have any suggestions / best practices to make this code faster?</p>