2024-09-27 07:32:33 发布
网友
我有一个包含多个最小值的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
temp2.ix[temp2.idxmin()]
我想取ABCD和MAN3作为最低要求??在
比较布尔索引的最小值
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
比较布尔索引的最小值
下一个解决方案是:
并且^{} 只返回一个值,因为:
并且^{} 在doc中解释这种情况:
您可以使用以下方法:
相关问题 更多 >
编程相关推荐