📜  Python|熊猫系列.isnull()

📅  最后修改于: 2022-05-13 01:54:59.908000             🧑  作者: Mango

Python|熊猫系列.isnull()

Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持整数和基于标签的索引,并提供了许多方法来执行涉及索引的操作。

Pandas Series.isnull()函数检测给定系列对象中的缺失值。它返回一个布尔值相同大小的对象,指示值是否为 NA。缺失值映射到True ,非缺失值映射到False

示例 #1:使用Series.isnull()函数检测给定系列对象中的缺失值。

# 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.isnull()函数来检测给定系列对象中的所有缺失值。

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

输出 :

正如我们在输出中看到的, Series.isnull()函数返回了一个包含布尔值的对象。所有值都已映射为False ,因为给定系列对象中没有缺失值。示例 #2:使用Series.isnull()函数检测给定系列对象中的缺失值。

# 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.isnull()函数来检测给定系列对象中的所有缺失值。

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

输出 :

正如我们在输出中看到的, Series.isnull()函数返回了一个包含布尔值的对象。所有缺失值都已映射到True