I would like to know how to get the mean value of a list which contains some NaNs. By using:
np.mean(mylist)
the result as expected gives NaN which is wrong. What should i do to get the mean?
Use np.nanmean to ignore the NaNs:
np.nanmean(mylist)
For example,
In [108]: np.nanmean([np.nan, 1, 2, np.nan, 3])
Out[108]: 2.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With