title: How to create new column in DataFrame based on other columns in Python Pandas?
body: <p>I have DataFrame like below:</p>
  <pre><code>data = pd.DataFrame({&quot;col1&quot; : [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], 
                       &quot;binary&quot; : [0, 1, 0]})
  </code></pre>
  <p>I would like to create and add new column in this <code>DataFrame</code> called <code>&quot;new&quot;</code> where if in column <code>&quot;binary&quot;</code> is 1 then I want to have data from <code>&quot;col1&quot;</code> in my created column <code>&quot;new&quot;</code>, but if in <code>&quot;binary&quot;</code> column is 0 then I want to have <code>np.NaN</code>. Below is the result which I really need based on my description and DatFrame above.</p>
  <p><a href="https://i.stack.imgur.com/HK1OF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HK1OF.png" alt="enter image description here" /></a></p>