當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Pandas Series.isna()用法及代碼示例

Pandas 係列是帶有軸標簽的一維ndarray。標簽不必是唯一的,但必須是可哈希的類型。該對象同時支持基於整數和基於標簽的索引,並提供了許多方法來執行涉及索引的操作。

Pandas Series.isna()函數檢測給定係列對象中的缺失值。它返回一個布爾值相同大小的對象,指示值是否為NA。缺失值被映射到True並且將非缺失值映射到False

用法: Series.isna()

參數:沒有

返回:布爾值

範例1:采用Series.isna()函數以檢測給定係列對象中的缺失值。

# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series([10, 25, 3, 25, 24, 6]) 
  
# Create the Index 
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp'] 
  
# set the index 
sr.index = index_ 
  
# Print the series 
print(sr)

輸出:

現在我們將使用Series.isna()函數以檢測給定係列對象中的所有缺失值。

# detect missing values 
result = sr.isna() 
  
# Print the result 
print(result)

輸出:

正如我們在輸出中看到的,Series.isna()函數已返回包含布爾值的對象。所有值都已映射到False因為給定係列對象中沒有缺失值。

範例2:采用Series.isna()函數以檢測給定係列對象中的缺失值。

# importing pandas as pd 
import pandas as pd 
  
# Creating the Series 
sr = pd.Series([11, 21, 8, 18, 65, None, 32, 10, 5, 24, None]) 
  
# Create the Index 
index_ = pd.date_range('2010-10-09', periods = 11, freq ='M') 
  
# set the index 
sr.index = index_ 
  
# Print the series 
print(sr)

輸出:

現在我們將使用Series.isna()函數以檢測給定係列對象中的所有缺失值。

# detect missing values 
result = sr.isna() 
  
# Print the result 
print(result)

輸出:

正如我們在輸出中看到的,Series.isna()函數已返回包含布爾值的對象。所有缺失值都已映射到True



相關用法


注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Series.isna()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。