7

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 ??

3 Answers 3

4

You could use following:

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

In [49]: df[df == df.min()].dropna()
Out[49]:
    1
0
ABCD  0
MAN3  0
Sign up to request clarification or add additional context in comments.

Comments

3

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.

1 Comment

@Anu - Use df2 = df[df.groupby('A')['C'].transform('min') == df['C']]
1

Compare the minimum value for Boolean indexing

df
Out[42]: 
             b
a             
ABCD  0.000000
JKLM  0.016535
CAN1  0.381729
MET2  0.275013
INDI  0.149280
MAN3  0.000000

df[df.b == df.b.min()]
Out[43]: 
      b
a      
ABCD  0
MAN3  0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.