Pandas数据帧中的多个最小值

2024-09-27 07:32:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含多个最小值的pandas数据帧,但是min函数只在列中选择一个。在

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

temp2.ix[temp2.idxmin()]只选取一个值ABCD with 0.0

我想取ABCD和MAN3作为最低要求??在


Tags: 数据函数pandaswithminixabcdindi
3条回答

比较布尔索引的最小值

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

下一个解决方案是:

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

并且^{}只返回一个值,因为:

This method is the DataFrame version of ndarray.argmin.

并且^{}doc中解释这种情况:

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

您可以使用以下方法:

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

In [49]: df[df == df.min()].dropna()
Out[49]:
    1
0
ABCD  0
MAN3  0

相关问题 更多 >

    热门问题