Pandas notnull(~)
方法返回一個布爾掩碼,其中 True
設置為非 NaN
值,False
設置為 NaN
。
參數
1.obj
| array-like
或 object
用於檢查非缺失值的類似數組(例如 Series、DataFrame、Numpy 數組、列表等)。
返回值
-
如果提供單個標量對象(例如字符串和數字),則返回單個
boolean
。 -
否則,返回布爾掩碼,其中
True
表示非NaN
值,False
表示NaN
。
例子
標量
pd.notnull("A")
True
pd.notnull(np.NaN)
False
pd.notnull(None)
False
Array-likes
Series
s = pd.Series([1,np.NaN,3])
pd.notnull(s)
0 True
1 False
2 True
dtype: bool
返回類型是布爾值Series
。
注意
係列具有 notna(~)
方法,其用途完全相同:
s = pd.Series([1,np.NaN,3])
s.notna()
0 True
1 False
2 True
dtype: bool
DataFrame
考慮以下 DataFrame :
df = pd.DataFrame({"A":[np.NaN,2], "B":[3,np.NaN]})
df
A B
0 NaN 3.0
1 2.0 NaN
要檢查現有值(非 NaN
值):
pd.notnull(df)
A B
0 False True
1 True False
返回類型是布爾值DataFrame
。
注意
DataFrames 具有 notna(~)
方法,其用途完全相同:
df = pd.DataFrame({"A":[np.NaN,2], "B":[3,np.NaN]})
df.notna()
A B
0 False True
1 True False
相關用法
- Python numpy string not_equal()用法及代碼示例
- Python NumPy not_equal方法用法及代碼示例
- Python Wand noise()用法及代碼示例
- Python now()用法及代碼示例
- Python Django non_atomic_requests用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python networkx.algorithms.shortest_paths.weighted.all_pairs_dijkstra_path用法及代碼示例
- Python numpy.polynomial.hermite.hermmul用法及代碼示例
- Python numpy.seterrobj用法及代碼示例
- Python networkx.classes.function.edge_subgraph用法及代碼示例
- Python numpy.tril()用法及代碼示例
- Python numpy.around用法及代碼示例
- Python networkx.algorithms.tree.mst.maximum_spanning_edges用法及代碼示例
- Python numpy.random.standard_normal()用法及代碼示例
- Python networkx.algorithms.bipartite.basic.color用法及代碼示例
- Python numpy.select用法及代碼示例
- Python networkx.algorithms.bipartite.cluster.latapy_clustering用法及代碼示例
- Python networkx.readwrite.json_graph.adjacency_data用法及代碼示例
- Python numpy.fft.irfft2用法及代碼示例
- Python numpy.polynomial.hermite_e.hermemul用法及代碼示例
- Python numpy.fft.irfftn用法及代碼示例
- Python numpy.nonzero()用法及代碼示例
- Python numpy.maximum_sctype()用法及代碼示例
- Python numpy.ma.dstack用法及代碼示例
- Python numpy.ma.make_mask_none()用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Pandas | notnull method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。