While trying to work on a project with pandas I have run into a problem. I had a list with a nan
value in it and I couldn’t remove it.
I have tried:
incoms=data['int_income'].unique().tolist()
incoms.remove('nan')
But it didn't work:
list.remove(x): x not in list"
The list incoms
is as follows:
[75000.0, 50000.0, 0.0, 200000.0, 100000.0, 25000.0, nan, 10000.0, 175000.0, 150000.0, 125000.0]
What you can do is simply get a cleaned list where you don't put the values that, once converted to strings, are 'nan'.
The code would be :
incoms = [incom for incom in incoms if str(incom) != 'nan']