pandas: slice dataframe based on NaN
<p>I have following dataframe <code>df</code></p>

<pre><code>prod_id prod_ref
10      ef3920
12      bovjhd
NaN     lkbljb
NaN     jknnkn
30      kbknkn
</code></pre>

<p>I am trying the following:</p>

<pre><code>df[df['prod_id'] != np.nan]
</code></pre>

<p>but I get exactly the same dataframe.</p>

<p>I would like to display</p>

<pre><code>prod_id prod_ref
10      ef3920
12      bovjhd
30      kbknkn
</code></pre>

<p>What am I doing wrong?</p>

<p>Use function <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.notnull.html" rel="nofollow"><code>notnull</code></a> or inverting <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isnull.html" rel="nofollow"><code>isnull</code></a>:</p>

<pre><code>print (df[df.prod_id.notnull()])
   prod_id prod_ref
0     10.0   ef3920
1     12.0   bovjhd
4     30.0   kbknkn

print (df[~df.prod_id.isnull()])

   prod_id prod_ref
0     10.0   ef3920
1     12.0   bovjhd
4     30.0   kbknkn
</code></pre>

<p>Another solution is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html" rel="nofollow"><code>dropna</code></a>, but need specify column for check <code>NaN</code>:</p>

<pre><code>print (df.dropna(subset=['prod_id']))
   prod_id prod_ref
0     10.0   ef3920
1     12.0   bovjhd
4     30.0   kbknkn
</code></pre>

<p>If in another columns are not <code>NaN</code> values, use <a href="http://stackoverflow.com/a/39601897/2901002">Alberto Garcia-Raboso's solution</a>.</p>

python python-2.7 pandas