title: Python Pandas: Apply function using column names as named arguments
body: <p>Is there a way in pandas to apply a function to a dataframe using the column names as argument names?  For example, I have a function and a dataframe.  </p>
  
  <pre><code>df = pd.DataFrame({'A':[1,2,3],
                 'B':[1,2,3],
                 'C':[1,2,3],
                 'D':[1,2,3]})    
  def f(A,B,C):
     #Pretend code is more complicated
     return A + B + C
  </code></pre>
  
  <p>Is there a way I can do something like</p>
  
  <pre><code>df.apply(f)
  </code></pre>
  
  <p>and have pandas match the columns to named arguments?</p>
  
  <p>I know I can rewrite the function to take a row instead of named arguments, but keep in mind that f is just a toy example and my real function is more complicated</p>
  
  <p>EDIT: </p>
  
  <p>Figured it out based @juanpa.arrivillaga answer:</p>
  
  <p><code>df[list(f.__code__.co_varnames)].apply((lambda row: f(**row)), axis=1)</code></p>