How can I remove Nan from list Python/NumPy

前端 未结 10 1951
挽巷
挽巷 2020-12-04 10:56

I have a list that countain values, one of the values I got is \'nan\'

countries= [nan, \'USA\', \'UK\', \'France\']

I tried to remove it,

10条回答
  •  没有蜡笔的小新
    2020-12-04 11:45

    use numpy fancy indexing:

    In [29]: countries=np.asarray(countries)
    
    In [30]: countries[countries!='nan']
    Out[30]: 
    array(['USA', 'UK', 'France'], 
          dtype='|S6')
    

提交回复
热议问题