title: pandas apply() with and without lambda
body: <p>What is the rule/process when a function is called with pandas <code>apply()</code> through lambda vs. not? Examples below. Without lambda apparently, the entire series ( df[column name] ) is passed to the "test" function which throws an error trying to do a boolean operation on a series. </p>
  
  <p>If the same function is called via lambda it works. Iteration over each row with each passed as "x" and the df[ column name ] returns a single value for that column in the current row.</p>
  
  <p>It's like lambda is removing a dimension. Anyone have an explanation or point to the specific doc on this?  Thanks.</p>
  
  <p><strong>Example 1 with lambda, works OK</strong></p>
  
  <pre><code>print("probPredDF columns:", probPredDF.columns)
  
  def test( x, y):
      if x==y:
          r = 'equal'
      else:
          r = 'not equal'
      return r    
  
  probPredDF.apply( lambda x: test( x['yTest'], x[ 'yPred']), axis=1 ).head()
  </code></pre>
  
  <p><strong>Example 1 output</strong></p>
  
  <pre><code>probPredDF columns: Index([0, 1, 'yPred', 'yTest'], dtype='object')
  
  Out[215]:
  0    equal
  1    equal
  2    equal
  3    equal
  4    equal
  dtype: object
  </code></pre>
  
  <p><strong>Example 2 without lambda, throws boolean operation on series error</strong></p>
  
  <pre><code>print("probPredDF columns:", probPredDF.columns)
  
  def test( x, y):
      if x==y:
          r = 'equal'
      else:
          r = 'not equal'
      return r    
  
  probPredDF.apply( test( probPredDF['yTest'], probPredDF[ 'yPred']), axis=1 ).head()
  </code></pre>
  
  <p><strong>Example 2 output</strong></p>
  
  <pre><code>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  </code></pre>