当前位置:网站首页>np.nan, np.isnan, None, pd.isnull, pd.isna finishing and summary
np.nan, np.isnan, None, pd.isnull, pd.isna finishing and summary
2022-08-02 12:08:00 【The big cat who wants to lie down every day】
np.nan, np.isnan, None, pd.isnull, pd.isna Sorting and summary
np.nan
np.nan | |
---|---|
not a member | nan的含义是“not a number“,它是对array中缺失的数值的占位符 |
type 为 float | As the missing value,np.nan的type是float |
可参与计算 | np.nan的type是float,所以np.nan可参与计算,And the dominance of,Is the calculated values arenp.nan |
不等于自身 | 如果用np.nan==np.nan,会发现返回的结果为False,如果用np.nan in array,也不能发现array中是否包含np.nan |
np.isnan判断是否存在np.nan | np.nanBecause there is no equal to the concept of,So to judge whether there isnp.nan,只可以用np.isnan来判断 |
np.isnanCan be judged only numeric | 如果用np.isnan对其余type的array判断,会报错,np.isnanCan be judged only Numbersarray |
忽略np.nan的numpy计算 |
---|
nansum() |
nanmax() |
nanmin() |
nanargmax() |
nanargmin() |
None
None | |
---|---|
NoneType | None的type为NoneType,是python内置的 |
不可参与计算 | None不可参与计算,否则报错 |
None is None 或者 None==None | Both the return value isTrue |
pd.isnull 和 pd.isna
pd.isnull pd.isna | |
---|---|
pd.isnull 和 pd.isna是同一个东西 | 用命令pd.isnull==pd.isna,Will find that the return value asTrue |
None和np.nan在pandasIs the default | None和np.nan都会被pd.isnull或者pd.isna判断为True |
可以判断ListOr a single value | pd.isnull和pd.isnaThe judgment of the object can be a value or alist |
pandasThe default values are not involved in calculation | 当使用df.min()When computing,Will find that the default values are not involved in calculation |
代码示例
- 只可以用np.isnan判断array中是否包含np.nan
a = np.array([1,2,3,4,np.nan])
a == np.nan
>>> array([False, False, False, False, False])
np.nan in a
>>> False
np.isnan(a)
>>> array([False, False, False, False, True])
- np.nan可参与计算,np.nan占主导地位
a = np.array([1,2,3,4,np.nan])
a.max()
>>> np.nan
a.min()
>>> np.nan
b = np.array([1,np.nan,3,4,5])
a+b
>>> array([ 2., nan, 6., 8., nan])
- np.isnanOnly can the numericarray判断,当arrayFor the rest of the element in the string is,array会将np.nan转换成’nan’
- 在pandas中,np.nan和NoneIs treated as the default
df = pd.DataFrame({
'col1':['a','b','c','d'], 'col2':[1,2,3,4]})
df.loc[1,'col1'] = np.nan
df.loc[2,'col1'] = None
df
>>> col1 col2
0 a 1
1 NaN 2
2 None 3
3 d 4
pd.isna(df)
>>> col1 col2
0 False False
1 True False
2 True False
3 False False
- pandasThe default values are not involved in calculation
df = pd.DataFrame(np.arange(8).reshape(2,4))
df.iloc[0,1] = None
df.iloc[0,2] = np.nan
df
>>> 0 1 2 3
0 0 NaN NaN 3
1 4 5.0 6.0 7
df.min(axis=1)
>>> 0 0.0
1 4.0
dtype: float64
边栏推荐
- Technology sharing | Description of the electronic fence function in the integrated dispatching system
- SQL function $TRANSLATE
- 8大软件供应链攻击事件概述
- darknet训练yolov4模型
- ABAP-OOAVL模板程序
- 【The 6th Strong Net Cup CTF-Wp】
- 【云驻共创】数据工坊平台,0代码开发数据处理业务“快”人一步
- redis cluster cluster, the ultimate solution?
- 技术分享| 融合调度系统中的电子围栏功能说明
- 云原生(三十) | Kubernetes篇之应用商店-Helm介绍
猜你喜欢
受邀出席Rust开发者大会|Rust如何助力量化高频交易?
Drools(8):WorkBench使用
QAbstractScrollArea、QScrollArea
MyCat2的介绍与安装以及基本使用
云原生(三十) | Kubernetes篇之应用商店-Helm介绍
面积曲线AUC(area under curve)
DTG-SSOD: The latest semi-supervised detection framework, Dense Teacher (with paper download)
力扣27-移除元素——简单题
用位运算为你的程序加速
Leek 151 - Reverse words in a string
随机推荐
Process finished with exit code 1
【Acunetix-Forgot your password】
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?
JVM学习----垃圾回收调优
Speed up your programs with bitwise operations
放苹果(暑假每日一题 13)
List排序 ,取最大值最小值
DTG-SSOD: The latest semi-supervised detection framework, Dense Teacher (with paper download)
doc2vec和word2vec(zigbee简介及应用)
Running yum reports Error: Cannot retrieve metalink for reposit
SQL函数 $TRANSLATE
力扣35-搜索插入位置——二分查找
npm install报错npm ERR Could not resolve dependency npm ERR peer
【项目管理技术的优势】
使用无界队列的线程池会导致内存飙升吗?
After Effects 教程,如何在 After Effects 中对蒙版进行动画绘制?
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一
JVM简介
手撸架构,Redis面试41问
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存