Python数据分析numpy的Nan和Inf使用注意点详解
作者:YiYa_咿呀
这篇文章主要为大家介绍了Python数据分析numpy的Nan和Inf使用注意点,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
numpy中的Nan
Nan:Not a number
np.count_nonzero(arr[type==bool]):判断数组内FALSE的个数
np.isnan(arr):返回值为arr值为nan的索引
Nan的注意点
1.两个nan是不相等的

应用
- 利用以上的特性,判断数组中nan的个数

- 将nan转换为0值

- nan和inf属于浮点类型

nan与任何数进行运算都是nan

numpy常见统计函数


import numpy as np
t1 = np.arange(12).reshape(3,4).astype(float)
t1[1,2:]=np.nan
print(t1)
for i in range(t1.shape[1]): # 对列进行循环
temp_col = t1[:,i] #选中当前的那一列
nan_col = np.nonzero(t1!=t1)
if nan_col != 0:
temp_non_nan_col = temp_col[temp_col==temp_col]
temp_col[np.isnan(temp_col)]=temp_non_nan_col.mean()
print(t1)
以上就是Python数据分析numpy的Nan和Inf使用注意点详解的详细内容,更多关于Python数据分析numpy Nan Inf的资料请关注脚本之家其它相关文章!
