title: Pandas assign - passing column in a user defined function
body: <p>Given an input dataframe and string:</p>
  <pre><code>df = pd.DataFrame({&quot;A&quot; : [10, 20, 30], &quot;B&quot; : [0, 1, 8]})
  colour = &quot;green&quot; #or &quot;red&quot;, &quot;blue&quot; etc.
  </code></pre>
  <p>I want to add a new column <code>df[&quot;C&quot;]</code> conditional on the values in <code>df[&quot;A&quot;]</code>, <code>df[&quot;B&quot;]</code> and <code>colour</code> so it looks like:</p>
  <pre><code>df = pd.DataFrame({&quot;A&quot; : [4, 2, 10], &quot;B&quot; : [1, 4, 3], &quot;C&quot; : [True, True, False]})
  </code></pre>
  <p>So far, I have a function that works for just the input values alone:</p>
  <pre><code>def check_passing(colour, A, B):
      if colour == &quot;red&quot;:
          if B &lt; 5:
              return True
          else:
              return False
      if colour == &quot;blue&quot;:
          if B &lt; 10:
              return True
          else:
              return False
      if colour == &quot;green&quot;:
          if B &lt; 5:
              if A &lt; 5:
                  return True
              else:
                  return False
          else:
              return False
  </code></pre>
  <p>How would you go about using this function in <code>df.assign()</code> so that it calculates this for each row? Specifically, how do you pass each column to <code>check_passing()</code>?</p>
  <p><code>df.assign()</code> allows you to refer to the columns directly or in a lambda, but doesn't work within a function as you're passing in the entire column:</p>
  <pre><code>df = df.assign(C = check_passing(colour, df[&quot;A&quot;], df[&quot;B&quot;]))
  </code></pre>
  <p>Is there a way to avoid a long and incomprehensible lambda? Open to any other approaches or suggestions!</p>