remove entries with nan values in python dictionary

后端 未结 4 1479
[愿得一人]
[愿得一人] 2021-01-18 12:47

I have the foll. dictionary in python:

OrderedDict([(30, (\'A1\', 55.0)), (31, (\'A2\', 125.0)), (32, (\'A3\', 180.0)), (43, (\'A4\', nan))])
4条回答
  •  失恋的感觉
    2021-01-18 13:22

    This should work:

    for k,v in dict_cg.items():
        if np.isnan(v[1]):
           dict_cg.pop(k)
    print dict_cg
    

    Output:

    OrderedDict([(30, ('A1', 55.0)), (31, ('A2', 125.0)), (32, ('A3', 180.0))])
    

提交回复
热议问题