title: Why isn't my Pandas 'apply' function referencing multiple columns working?
body: <p>I have some problems with the Pandas apply function, when using multiple columns with the following dataframe</p>
  
  <pre><code>df = DataFrame ({'a' : np.random.randn(6),
                   'b' : ['foo', 'bar'] * 3,
                   'c' : np.random.randn(6)})
  </code></pre>
  
  <p>and the following function</p>
  
  <pre><code>def my_test(a, b):
      return a % b
  </code></pre>
  
  <p>When I try to apply this function with :</p>
  
  <pre><code>df['Value'] = df.apply(lambda row: my_test(row[a], row[c]), axis=1)
  </code></pre>
  
  <p>I get the error message:</p>
  
  <pre><code>NameError: ("global name 'a' is not defined", u'occurred at index 0')
  </code></pre>
  
  <p>I do not understand this message, I defined the name properly. </p>
  
  <p>I would highly appreciate any help on this issue</p>
  
  <p>Update</p>
  
  <p>Thanks for your help. I made indeed some syntax mistakes with the code, the index should be put ''. However I still get the same issue using a more complex function such as:</p>
  
  <pre><code>def my_test(a):
      cum_diff = 0
      for ix in df.index():
          cum_diff = cum_diff + (a - df['a'][ix])
      return cum_diff 
  </code></pre>