Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Minimum Values in Pandas Dataframe

Tags:

python

pandas

I have a pandas dataframe of multiple minimum values but the min functions picks only one on the column.

 ABCD     0.000000
 JKLM     0.016535
 CAN1     0.381729
 MET2     0.275013
 INDI     0.149280
 MAN3     0.000000

temp2.ix[temp2.idxmin()] only picks one value that is ABCD with 0.0

I would like to fetch both ABCD and MAN3 as minimum ??

like image 361
sane Avatar asked Dec 01 '15 06:12

sane


2 Answers

You could use following:

df[df == df.min()].dropna()

In [49]: df[df == df.min()].dropna()
Out[49]:
    1
0
ABCD  0
MAN3  0
like image 125
Anton Protopopov Avatar answered Sep 19 '22 12:09

Anton Protopopov


Next solution is:

df.where(df == df.min()).dropna()

And df.idxmin() return only one value, because:

This method is the DataFrame version of ndarray.argmin.

And ndarray.argmin explain this situation in doc:

In case of multiple occurrences of the minimum values, the indices corresponding to the first occurrence are returned.

like image 37
jezrael Avatar answered Sep 19 '22 12:09

jezrael