NaN元组列表(字符串,浮点数)如何获取最小值? [英] List of Tuples (string, float)with NaN How to get the min value?

查看:46
本文介绍了NaN元组列表(字符串,浮点数)如何获取最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带 float('nan')的元组列表(字符串,浮点数).我怎样才能得到最小的元组?如果我使用min,我总是会得到 nan .

I have a list of List of Tuples (string, float) with float('nan'). How can i get the tuple with the smallest number? If I use min I always get the nan.

[('GroundBasedMechWT', nan), ('GroundBasedCTL', nan), ('GroundBasedManualWT', nan), ('GroundBasedManualLog', nan), ('CableManualWTLog', 60.77), ('CableManualWT', 58.52), ('CableManualLog', 68.17), ('CableManualCTL', nan), ('HelicopterManualWT', 96.82), ('HelicopterManualCTL', nan)]

推荐答案

您也可以尝试以下方法:

You could also try this:

min(filter(lambda t: not math.isnan(t[1]), l), key=itemgetter(1))

其中 itemgetter 是指 operator.itemgetter .

这篇关于NaN元组列表(字符串,浮点数)如何获取最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆