Oct-05-2021, 04:17 PM
You should tell where the list come from(not a dict) as it has
When use eg NumPy, Pandas the way to solve can be very different from doing it in stander Python.
So it can be done like this.
nan
lowercase it most likely come from NumPy. When use eg NumPy, Pandas the way to solve can be very different from doing it in stander Python.
nan
will give a error so menator01 has solved it by using nan = 0
,not ideal but that because of lacking information from OP as mention.So it can be done like this.
# Give error >>> lst = [438.4, 439.18, 439.9, 440.21999999999997, 440.38, 441.08000000000004, nan, nan, nan, nan] Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'nan' is not defined >>> import numpy as np >>> from numpy import nan # Fix error >>> >>> lst = [438.4, 439.18, 439.9, 440.21999999999997, 440.38, 441.08000000000004, nan, nan, nan, nan] >>> [x for x in lst if ~np.isnan(x)] [438.4, 439.18, 439.9, 440.21999999999997, 440.38, 441.08000000000004]