pandas 失败:使用.idxmin()查找最小值时重复出现问题

dzjeubhm  于 2022-12-02  发布在  其他
关注(0)|答案(1)|浏览(132)

示例数据:

Fitness Value   MSU Locations   MSU Range
1.045426         {13, 38, 15}   2.213424
1.096542         {9, 38, 39}    2.226205
1.226040         {1, 22, 30}    1.871269
1.045426         {13, 38, 15}   2.213424
1.096542         {9, 38, 39}    2.226205
1.143814         {26, 19, 20}   2.223852
1.045426         {13, 38, 15}   2.213424
1.096542         {9, 38, 39}    2.226205
1.143814         {26, 19, 20}   2.223852

我尝试在Fitness Value列中查找minimum value,并保留整行记录。

样品代码:

WATT = df_min_value_in_each_generation.loc[df_min_value_in_each_generation['Fitness Value'].idxmin()]
WATT

输出:

Fitness Value   MSU Locations   MSU Range
1.045426        {13, 38, 15}    2.213424
1.158718        {29, 22, 39}    2.143414
1.045426        {13, 38, 15}    2.213424
1.139776         {18, 3, 23}    1.599072
1.045426        {13, 38, 15}    2.213424
1.136302        {17, 10, 13}    2.217177

我只想打印最小的值,但它打印多个值(也是重复的)。任何解决方案?

ee7vknir

ee7vknir1#

尝试使用以下代码,它可以处理重复项。

WATT = df_min_value_in_each_generation.loc[df_min_value_in_each_generation['Fitness Value'].eq(df['Fitness Value'].min())]

WATT

相关问题