当前位置:网站首页>[numpy] numpy's judgment on Nan value
[numpy] numpy's judgment on Nan value
2022-06-24 03:44:00 【When Camellia blossoms.】

numpy.nan The data type of is float type
import numpy as np
type(np.nan) # float
Any number and numpy.nan Calculate , All the returned results are nan
import numpy as np
print(np.nan + 1) # nan
print(np.nan - 1) # nan
print(np.nan * 1) # nan
print(np.nan / 1) # nan For null values NaN The judgment of cannot be used directly == expression ,bool expression , And can not be used directly if sentence Judge
import numpy as np
np.nan == np.nan # False
bool(np.nan) # True
# Output results :na is not null
if np.nan:
print('np.nan is not null') Need to use Numpy Own method np.isnan(),is expression ,in expression Judge
import numpy as np
np.nan is np.nan # True
np.isnan(np.nan) # True
np.nan in [np.nan] # True
Tips
If you use Pandas To judge numpy.nan, You can use pd.isnull(),pd.isna()
import numpy as np import pandas as pd pd.isnull(np.nan) # True pd.isna(np.nan) # True
Be careful :None、NaN、'' The difference between empty strings
# None yes Python Special types of
# NoneType object , It has only one value None
type(None) # NoneType
None == None # True
None == np.nan # False
# An empty string ''
type('') # strPandas Medium pd.isnull Not only can it be detected np.nan It can also detect None, but Cannot detect string , such as '','nan','None'
import pandas as pd
import numpy as np
pd.isnull(np.nan) # True
pd.isnull(None) # True
pd.isnull('') # False
pd.isnull('np.nan') # False
pd.isnull('None') # Falseimport pandas as pd
import numpy as np
List = ['nan', '', 'None', None, np.nan]
for i in List:
if i == '' or pd.isnull(i) or pd.isnull(float('nan')) or i == 'None':
print(i)
# The above output results :
# nan
# ''
# None
# None
# nanList(5 elements)

边栏推荐
- Modstartcms enterprise content site building system (supporting laravel9) v4.2.0
- How to build glasses website what are the functions of glasses website construction
- Cross platform RDP protocol, RDP like protocol and non RDP protocol remote software
- The quick login of QQ cannot be directly invoked through remote login, and the automatic login of QQ can be invoked using VNC
- Spirit breath development log (17)
- How do websites use CDN? What are the benefits of using it?
- [code Capriccio - dynamic planning] t392 Judgement subsequence
- 黑帽SEO实战搜索引擎快照劫持
- 黑帽实战SEO之永不被发现的劫持
- 黑帽SEO实战之通用301权重pr劫持
猜你喜欢

QT creator tips

Pine Script脚本常用内容

浅谈游戏安全 (一)

黑帽SEO实战之通用301权重pr劫持

On Sunday, I rolled up the uni app "uview excellent UI framework"

老弹出explorer.exe遇到问题已停止工作,怎么办?

【代码随想录-动态规划】T392.判断子序列

618 promotion: mobile phone brand "immortal fight", high-end market "who dominates the ups and downs"?

Halcon knowledge: contour operator on region (2)

黑帽SEO实战搜索引擎快照劫持
随机推荐
What technology does cloud computing elasticity scale? What are the advantages of elastic scaling in cloud computing?
What is the difference between elasticity and scalability of cloud computing? What does elastic scaling of cloud computing mean?
左滑从小窗到大窗口DispatchFrameLayout
黑帽SEO实战之目录轮链批量生成百万页面
13. Tencent cloud IOT device side learning - data template function and Implementation
Troubleshooting and resolution of errors in easycvr calling batch deletion interface
Industrial security experts talk about how to build security protection capability for government big data platform?
[competition experience sharing] design of intelligent guide rod
What is edge computing? What are the characteristics of the Internet platform edge calculator?
How to choose excellent server hosting or server leasing in Beijing
Why do I need a code signing certificate? Where can I get a code signing certificate?
Koom of memory leak
Disk partition extension using graphical interface and PowerShell code
web rdp Myrtille
On game safety (I)
黑帽SEO实战搜索引擎快照劫持
Understand Devops from the perspective of leader
take the crown! Tencent security won the 2021 national network security week outstanding innovation achievement award
Slide left from small window to large windowdispatchframelayout
How do websites use CDN? What are the benefits of using it?