📜  Python|熊猫 Index.notnull()

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

Python|熊猫 Index.notnull()

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas Index.notnull()函数检测现有(非缺失)值。此函数返回一个布尔值相同大小的对象,指示值是否不为 NA。非缺失值被映射为 True。空字符串” 或 numpy.inf 等字符不被视为 NA 值(除非您设置 pandas.options.mode.use_inf_as_na = True)。 NA 值,例如 None 或 numpy.NaN,被映射到 False 值。

示例 #1:使用Index.notnull()()函数检测给定索引中的缺失值。

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index(['Jan', '', 'Mar', None, 'May', 'Jun', 'Jul',
                         'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
  
# Print the Index
idx

输出 :

让我们找出索引中的所有非缺失值

# to find the non-missing values.
idx.notnull()

输出 :

正如我们在输出中看到的那样,所有非缺失值都已映射到True并且所有缺失值都已映射到False 。请注意,空字符串已映射为True ,因为空字符串不被视为缺失值。

示例 #2:使用Index.notnull()函数找出索引中的所有非缺失值。

# importing pandas as pd
import pandas as pd
  
# Creating the index
idx = pd.Index([22, 14, 8, 56, None, 21, None, 23])
  
# Print the Index
idx

输出 :

让我们找出索引中的所有非缺失值

# to find the non-missing values.
idx.notnull()

输出 :

正如我们在输出中看到的那样,所有非缺失值都已映射到True并且所有缺失值都已映射到False