title: python dynamic fuzzy logic join
body: <p>I am trying to make a dynamic fuzzy logic join for 2 tables. What I mean by dynamic is allowing the arguments to specify the variables that will allow the two tables to join. 
  The code noted below is a modified version of the static code under the following link:
  <a href="https://stackoverflow.com/questions/19964546/python-pandas-fuzzy-merge-match-with-duplicates">Python Pandas fuzzy merge/match with duplicates</a></p>
  
  <p>I have compiled the dynamic code below:</p>
  
  <pre><code>import pandas as pd
  import datetime
  from fuzzywuzzy import fuzz
  import difflib 
  
  donors = pd.DataFrame({"name": pd.Series(["John Doe","John Doe","Tom Smith","Jane Doe","Jane Doe","Kat test"]), "Email": pd.Series(['a@a.ca','a@a.ca','b@b.ca','c@c.ca','something@a.ca','d@d.ca']),"Date": (["27/03/2013  10:00:00 AM","1/03/2013  10:39:00 AM","2/03/2013  10:39:00 AM","3/03/2013  10:39:00 AM","4/03/2013  10:39:00 AM","27/03/2013  10:39:00 AM"])})
  fundraisers = pd.DataFrame({"name": pd.Series(["John Doe","John Doe","Kathy test","Tes Ester", "Jane Doe"]),"Email": pd.Series(['a@a.ca','a@a.ca','d@d.ca','asdf@asdf.ca','something@a.ca']),"Date": pd.Series(["2/03/2013  10:39:00 AM","27/03/2013  11:39:00 AM","3/03/2013  10:39:00 AM","4/03/2013  10:40:00 AM","27/03/2013  10:39:00 AM"])})
  donors["Date"] = pd.to_datetime(donors["Date"], dayfirst=True)
  fundraisers["Date"] = pd.to_datetime(donors["Date"], dayfirst=True)
  donors["code"] = donors.apply(lambda row: str(row['name'])+' '+str(row['Email']), axis=1)
  idx = donors.groupby('code')["Date"].transform(min) == donors['Date']
  donors = donors[idx].reset_index().drop('index',1)
  
  def get_donors_v1(fund_var,don_var, don_tab,row=None):
      d = don_tab.apply(lambda x: fuzz.ratio(x["%s" % don_var], 'row["%s" %fund_var]') * 2, axis=1)
      d = d[d &gt;= 75]
      if len(d) == 0:
          v = ['']*3
      else:
          v = don_tab.ix[d.idxmax(), ["%s"% don_var ,'Email','Date']].values
      return pd.Series(v, index=['donor name', 'donor email', 'donor date'])
  
  trial=pd.concat((fundraisers, fundraisers.apply(get_donors_v1(fund_var="name",don_var="name",don_tab=donors), axis=1)), axis=1)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>TypeError: get_donors_v1() takes exactly 4 arguments (3 given)</p>
  </blockquote>
  
  <p>Should I replace the function to: </p>
  
  <pre><code>get_donors_v1(row=None,fund_var,don_var, don_tab)
  </code></pre>
  
  <p>then i get the following error:</p>
  
  <blockquote>
    <p>TypeError: ("'NoneType' object has no attribute '<strong>getitem</strong>'",
    u'occurred at index 0')</p>
  </blockquote>
  
  <p>please help.</p>