Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to drop 'NAN' values from a list

 def remove_sel(l1, l2):
 return [z1 for z1, z2 in zip(l1, l2) if z2>=0]

works nicely to remove negatives values of a list but if my list is z=[1, 2, 3, 'NAN']

Ps I wonder if my list is z or z'=['1','2', '3','NAN']

I have tried

math import isnan
zz = [x for x in z if not isnan(x)]

How to drop 'NAN' values from a list

I rewrite my question : I have the followinbg list z=[-1, 0, 1, 2, 3, 'Toto'] def remove_sel(l1, l2): return [z1 for z1, z2 in zip(l1, l2) if z2>=0]

works nicely and I want to remove negatives values of create a list but if my list is composqe of strictly positive numbers (whichever type they are) and without z=[1, 2, 3, 'NAN']toto

Ps I wonder if my list is z or z'=['1','2', '3','NAN']

I have tried

math import isnan
zz = [x for x in z if not isnan(x)]