[英]Get the mean value of list containing NaNs in Python
I would like to know how to get the mean value of a list which contains some NaNs. 我想知道如何获取包含某些NaN的列表的平均值。 By using:
通过使用:
np.mean(mylist)
the result as expected gives NaN which is wrong. 预期结果显示NaN错误。 What should i do to get the mean?
我该怎么做才能得到平均值?
Use np.nanmean to ignore the NaNs: 使用np.nanmean忽略NaN:
np.nanmean(mylist)
For example, 例如,
In [108]: np.nanmean([np.nan, 1, 2, np.nan, 3])
Out[108]: 2.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.