title: How to Pass Pandas Dataframe and Column to a Function
body: <p>So I have a large amount of columns within a pandas dataframe and I need to pass groups of them through a function. The function is large but I'll create an example below. I am not sure how to pass the reference of df.varName to the function without getting the issue of the variable not being defined. When I try a function such as:</p>
  
  <pre><code>def bianco2(df, varX, varT):
      stdX = np.std(df.varX)
      stdT = np.std(df.varT)
      newVar = stdX + stdT
      return newVar
  </code></pre>
  
  <p>I get the error that varX isn't defined. So I wrote the function where I would pass the whole phrase:</p>
  
  <pre><code>def bianco3(varX, varT):
      stdX = np.std(varX)
      stdT = np.(varT)
      newVar = stdX + stdT
      return newVar
  </code></pre>
  
  <p>Where "varX = df.varX".</p>
  
  <p>This worked but isn't practical for a large number of variables because I would still have to manually update each varX and varT. So I tried creating a list of variables in the format df.varX and then using a for loop to pass the list of variables. The issue is python sees it as a string and not a reference. I looked at using functools.partial but was unsuccessful.</p>
  
  <p>Any ideas on how to write this in a simple format and be able to pass panda columns to a function?</p>