Home > Enterprise >  How to search for NaNs in a loop?
How to search for NaNs in a loop?

Time:05-05

I've created a list than continues NaN values. I want to be able to count these NaN values in a For loop and add them to a variable so I can count the total number of Nan values, does anyone have any ideas for this?

Thanks.

CodePudding user response:

NaN should be the only value returning false on self equality:

nan_count = [value for value in my_list if value != value]

CodePudding user response:

If you want the count, you get it with

import numpy as np
my_arr = np.array(my_list)
count = (my_arr != my_arr).sum()
  • Related