title: Pandas return DataFrame from apply function?
body: <pre><code>sdf = sdf['Name1'].apply(lambda x: tryLookup(x, tdf))
  </code></pre>
  
  <p><code>tryLookup</code> is a function that is currently taking a string, which is the value of <code>Name1</code> in the sdf column. We map the function using apply to every row in the <code>sdf</code> DataFrame.</p>
  
  <p>Instead of <code>tryLookup</code> returning just a string, is there a way for <code>tryLookup</code> to return a DataFrame that I want to merge with the <code>sdf</code> DataFrame? <code>tryLookup</code> has some extra information, and I want to include that in the results by adding them as new columns to all the rows in <code>sdf</code>.</p>
  
  <p>So the return for <code>tryLookup</code> is as such:</p>
  
  <pre><code>return pd.Series({'BEST MATCH': bestMatch, 'SIMILARITY SCORE': humanScore})
  </code></pre>
  
  <p>I tried something such as </p>
  
  <pre><code>sdf = sdf.merge(sdf['Name1'].apply(lambda x: tryLookup(x, tdf)), left_index=True, right_index=True)
  </code></pre>
  
  <p>But that just throws</p>
  
  <pre><code>Traceback (most recent call last):
    File "lookup.py", line 160, in &lt;module&gt;
      main()
    File "lookup.py", line 40, in main
      sdf = sdf.merge(sdf['Name1'].apply(lambda x: tryLookup(x, tdf)), left_index=True, right_index=True)
    File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 4618, in merge
      copy=copy, indicator=indicator)
    File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 58, in merge
      copy=copy, indicator=indicator)
    File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 473, in __init__
      'type {0}'.format(type(right)))
  ValueError: can not merge DataFrame with instance of type &lt;class 'pandas.core.series.Series'&gt;
  </code></pre>
  
  <p>Any help would be great. Thanks.</p>