title: How do you add a calculated column to a pandas dataframe using set-based logic?
body: <p>I'm new to python (background in T-SQL and R) and looking for a set-based method for adding a calculated column to a Pandas Dataframe. R and T-SQL have simple implementations for this concept, but I've yet to find a solution to this in Python.</p>
  
  <p><a href="https://stackoverflow.com/questions/24976274/adding-a-calculated-column-to-pandas-dataframe">This question</a> is an iterative approach to what I'm looking for. I'm looking for something more set-based, and have yet to find a solution. </p>
  
  <p>Here is an example from R:</p>
  
  <pre><code># New column that shows if the value in column A is greater than the value in column B
  
  myDataFrame$CalculatedColumn = ifelse(myDataFrame$columnA &gt; myDataFrame$columnB,TRUE,FALSE)
  </code></pre>
  
  <p>This statement will add a new calculated column without requiring row-by-row evaluation code.</p>
  
  <p>Does Python (or any Python packages) support a concept like this? Or is the most practical solution way to call iterrows() in a for loop?</p>
  
  <p>Let me know if any clarifications are needed - and thanks for the help!</p>