argmin in dataset containing NaN python
<pre><code>      SGSIN VNVUT CNSHK HKHKG JPOSA
To                                 
MYPKL     1     4     8     9    13
SGSIN   NaN     3     7     8    12
VNVUT   NaN   NaN     3     4     8
CNSHK     1   NaN   NaN     1     5
HKHKG   NaN   NaN   NaN   NaN     3
</code></pre>

<p>Let say we have the above dataset using pandas. I want to calculate the <code>arg_minimum</code> over the first column and ignoring the <code>NaN</code>. I tried with </p>

<pre><code>df[df[0]].idxmin()
</code></pre>

<p>but it gives </p>

<pre><code>nan
</code></pre>

<p>but I don't get the right result then. Can someone help me?  The result I want is (in this case) </p>

<pre><code>[0,3]
</code></pre>

<p>You can use numpy's <code>argwhere</code></p>

<pre><code>import numpy as np

np.argwhere(df['SGSIN'].eq(df['SGSIN'].min()))

array([[0],
       [3]])
</code></pre>

python pandas machine-learning