title: Converting Python Function and For Loop into OOP Class and Methods
body: <p><em><strong>I have a Function and a For Loop that I am using to fuzzy match records from two Dataframe that I would like to convert to OOP. When I create the function then call the function in a for loop, I receive a Dataframe of the matched results. When I try to implement the Function and For Loop using OOP, I receive a <code>TypeError: fuzzy_sort_ratio() takes 1 positional argument but 4 were given</code>. How do I receive the matched results using OOP?</strong></em></p>
  <h3>Here is the Function</h3>
  <pre><code>def match_name(name, list_names, min_score=0):
  
      # -1 score incase we don't get any matches
      max_score = -1
  
      # Returning empty name for no match as well
      max_name = &quot;&quot;
  
      # Iterating over all names in the second list
      for name2 in list_names:
  
          #Finding fuzzy match score
          score = fuzz.token_sort_ratio(name, name2)
  
          # Checking if we are above our threshold and have a better score
          if (score &gt; min_score) &amp; (score &gt; max_score):
              max_name = name2
              max_score = score
  
      return (max_name, max_score)
  </code></pre>
  <h3>Here is the For Loop</h3>
  <pre><code>
  # List for dicts for easy DataFrame creation
  
  dict_list = []
  
  # iterating over df with more strains
  for name in nielParent:
  
      # Use our method to find best match, we can set a threshold here
      match = match_name(name, df['col_name'], 50)
      
      # New dict for storing data
      dict_ = {}
      dict_.update({&quot;Column_Name&quot; : name})
      dict_.update({&quot;Generic_Company&quot; : match[0]})
      dict_.update({&quot;score&quot; : match[1]})
      dict_list.append(dict_)
      
  merge_table = pd.DataFrame(dict_list)
  </code></pre>
  <h3>What I tried to implement using OOP</h3>
  <pre><code>class FuzzyMatch: 
      def __init__(self, name, list_names, min_score):
          self.name = name 
          self.list_names = list_names
          self.min_score = min_score
          
      def fuzzy_sort_ratio(self):
          
          # -1 score incase we don't get any matches 
          max_score = -1 
          
          # Return empty name for no match
          max_name = &quot;&quot;
          
          # List for dicts for easy DataFrame creation
          dict_list = []
          
          # Iterating over all names in second list 
          for name2 in self.list_names: 
          
              # Finding Fuzzy match score
              score = fuzz.token_sort_ratio(self.name,  name2)
              
              
              # Checking if we are above out threshold and have a better score 
              if (score &gt; self.min_score) &amp; (score &gt; max_score): 
                  max_name = name2
                  max_score = score 
                  
          return (max_name, max_score)
      
      def filteredFuzzy(self):
          
          # List for dicts for easy DataFrame creation
          dict_list = []
      
      # iterating over df with more strains
          for var in self.name:
  
          # Use our method to find best match, we can set a threshold here
              match = self.fuzzy_sort_ratio(var, self.list_names, self.min_score)
      
              # New dict for storing data
              dict_ = {}
              dict_.update({&quot;Column_Name&quot; : var})
              dict_.update({&quot;Generic_COMPANY&quot; : match[0]})
              dict_.update({&quot;MATCHING_SCORE&quot; : match[1]})
              dict_list.append(dict_)
  
          filtered = pd.DataFrame(dict_list)
          return filtered.sort_values(by='MATCHING_SCORE', ascending = False)
  </code></pre>
  <h3>Calling the OOP Function</h3>
  <pre><code>a = FuzzyMatch(name= df['col_name'], list_names=df2['PrivateName'], min_score=50)
  a.filteredFuzzy()
  
  </code></pre>
  <h3>UPDATE</h3>
  <pre><code>class FuzzyMatch: 
  #     def __init__(self, name, list_names):
  #         self.name = name 
  #         self.list_names = list_names
  #         #self.min_score = min_score
          
      def fuzzy_sort_ratio(self, name, list_names, min_score):
          
          # -1 score incase we don't get any matches 
          max_score = -1 
          
          # Return empty name for no match
          max_name = &quot;&quot;
          
          # List for dicts for easy DataFrame creation
          dict_list = []
          
          # Iterating over all names in second list 
          for name2 in list_names: 
          
              # Finding Fuzzy match score
              score = fuzz.token_sort_ratio(name,  name2)
              
              
              # Checking if we are above out threshold and have a better score 
              if (score &gt; min_score) &amp; (score &gt; max_score): 
                  max_name = name2
                  max_score = score 
                  
          return (max_name, max_score)
      
      def filteredFuzzy(self, name, list_names, min_score):
          
          # List for dicts for easy DataFrame creation
          dict_list = []
      
      # iterating over df with more strains
          for var in name:
          # Use our method to find best match, we can set a threshold here
              match = self.fuzzy_sort_ratio(var, list_names, min_score)
      
              # New dict for storing data
              dict_ = {}
              dict_.update({&quot;COMPANY_NAME&quot; : var})
              dict_.update({&quot;GENERIC_COMPANY&quot; : match[0]})
              dict_.update({&quot;MATCHING_SCORE&quot; : match[1]})
              dict_list.append(dict_)
  
          filtered = pd.DataFrame(dict_list)
          return filtered.sort_values(by='MATCHING_SCORE', ascending = False)
  </code></pre>
  <p><em>I was able to get the OOP method to return the matched results by removing the __init__ method and specifying the parameters in fuzzy_sort_ratio and filteredFuzzy methods. If the inputs are the same for both functions, what am I doing wrong by using the __init__ method?</em></p>