[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.09034446 0.16660596 0.20366712 0.21721049 0.22288556 0.2647726 0.30133098 0.35875865 0.67048766 0.83591387 0.84130192 1.00343632 1.08201832 1.32280598 3.71048433 4.92399325 5.7334934 5.78915343 5.79743345 11.87101934 nan nan nan nan nan] In this list, I want to remove nan values and keep only the floating-point values.
Asked
Active
Viewed 649 times
1 Answers
0
if your nan values are np.nan use this
l = [x for x in yourlist if ~np.isnan(x)]
if they are just nans use this
cleanedList = [x for x in yourlist if str(x) != 'nan']

Varadharajan Raghavendran
- 163
- 1
- 12