Remove a tuple containing nan in list of tuples — Python

后端 未结 4 452
心在旅途
心在旅途 2021-01-24 12:13

I have a long list of tuples and want to remove any tuple that has a nan in it using Python.

What I currently have: x = [(\'Recording start\', 0), (nan, 4), (nan, 7

4条回答
  •  遇见更好的自我
    2021-01-24 12:32

    At least at my python usage of nan retured the 'not defined error', this is why I defined it by my self. I think you can use a Python filter function for yor needs. See the example:

    nan = float('nan')
    lst = [('Recording start', 0), (nan, 4), (nan, 7), ('Event marker 1', 150)]
    y = filter( lambda x: nan not in x, lst)
    print y
    

    [('Recording start', 0), ('Event marker 1', 150)]

提交回复
热议问题