title: How to combine two columns conditionally based on a third
body: <p>Suppose I have a df with four columns, all with a shared time series index. I need to merge column1 and column2 into a new column4 conditionally based on column3. im new to python and jumped straight to a failed for loop as follows</p>
  <pre><code>for i in df.column3.index:
      if df.loc[i, &quot;column1&quot;] &gt; 180:
          df.loc[i, &quot;column4&quot;] = df[&quot;column1&quot;]
      elif df.loc[i, &quot;column1&quot;] &lt; 180:
          df.loc[i, &quot;column4&quot;] = df[&quot;column2&quot;]
  </code></pre>
  <p>I'm hoping someone can suggest a solution.
  thanks,</p>