title: Fuzzy matching only for values within same group
body: <p>I am stuck with this problem that should have a simple solution but I cannot find it.</p>
  <p>I have two data frames:</p>
  <p>dfA</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Company</th>
  <th>Country Code</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>CompanyA</td>
  <td>IT</td>
  </tr>
  <tr>
  <td>CompanyB</td>
  <td>DE</td>
  </tr>
  <tr>
  <td>CompanyC</td>
  <td>DE</td>
  </tr>
  <tr>
  <td>CompanyD</td>
  <td>SE</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>dfB</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Company</th>
  <th>Country Code</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Company A</td>
  <td>IT</td>
  </tr>
  <tr>
  <td>Company B</td>
  <td>DE</td>
  </tr>
  <tr>
  <td>Company C</td>
  <td>DE</td>
  </tr>
  <tr>
  <td>Company D</td>
  <td>SE</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Dataframe B contains the correct spelling of the company names so I am trying to get a match using the fuzzywuzzy library. So far I got good similarity scores but I would like to further improve them by only comparing companies with the same country code.</p>
  <p>This is the code I have been running so far:</p>
  <pre><code>import pandas as pd
  from fuzzywuzzy import process, fuzz
  
  actual_name = []
  similarity = []
  
  for i in dfA[&quot;Company&quot;]:
          ratio = process.extract( i, dfB[&quot;Company&quot;], limit=1)
          actual_name.append(ratio[0][0])
          similarity.append(ratio[0][1])
          
  dfA['actual_name'] = pd.Series(actual_name)
  dfA['similarity'] = pd.Series(similarity)
  
  </code></pre>
  <p>How can I improve my code so that company names are compared only if for i dfA[&quot;Country Code&quot;] == dfB[&quot;Country Code&quot;]?</p>