If statement in python Pandas
<p>I've a dataframe called family in pandas that I've created following an sql code. I've done all of it except this line. The sql code is the following </p>

<pre><code>SELECT IF(name Is Null, family.last_name, family.first_name) as family.NAME
from family
</code></pre>

<p>I've tried the following </p>

<pre><code>family['NAME']= np.where(family[family.name.isnull()],family.last_name, family.first_name)
</code></pre>

<p>But I'm not getting anywhere, any help is appreciated. The dataframe looks something like this </p>

<pre><code>name:    first_name:    last_name:
Peter    Peter          Smith
NaN      Phil           McGrath
Jack     Jack           Jones
NAN      Fred           Hogan 
</code></pre>

<p>I want it to get me a new column that would look like this </p>

<pre><code>NAME:
Peter
McGrath
Jack
Hogan
</code></pre>

<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">numpy.where(condition[, x, y])</a> function expects <code>bool</code> values as a <code>condition</code> argument:</p>

<blockquote>
  <p><strong>condition :</strong> array_like, bool</p>
  
  <p>When True, yield x, otherwise yield y.</p>
</blockquote>

<p>so you can do it this way:</p>

<pre><code>np.where(family.name.isnull(),family.last_name, family.first_name)
</code></pre>

python sql pandas