How can I remove Nan from list Python/NumPy

前端 未结 10 1904
挽巷
挽巷 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:51

    I noticed that Pandas for example will return 'nan' for blank values. Since it's not a string you need to convert it to one in order to match it. For example:

    ulist = df.column1.unique() #create a list from a column with Pandas which 
    for loc in ulist:
        loc = str(loc)   #here 'nan' is converted to a string to compare with if
        if loc != 'nan':
            print(loc)
    

提交回复
热议问题