Python Pandas IntervalIndex - 检查缺失值的区间是否为空
要检查缺失值的区间是否为空,请使用IntervalIndex.is_empty属性。首先,导入所需的库 -
import pandas as pdimport numpy as np
使用 NaN 值创建 IntervalIndex -
interval = pd.IntervalIndex.from_arrays([np.nan, np.nan], [np.nan, np.nan])
显示间隔 -
print("IntervalIndex...\n",interval)
检查包含缺失值的区间是否为空 -
print("\nIs the interval empty?\n",interval.is_empty)
示例
以下是代码 -
import pandas as pd输出结果import numpy as np
# 使用 NaN 值创建 IntervalIndex
interval = pd.IntervalIndex.from_arrays([np.nan, np.nan], [np.nan, np.nan])
# 显示间隔
print("IntervalIndex...\n",interval)
# 显示间隔 length
print("\nIntervalIndex length...\n",interval.length)
# 检查包含缺失值的区间是否为空
print("\nIs the interval empty?\n",interval.is_empty)
这将产生以下输出 -
IntervalIndex...IntervalIndex([nan, nan], dtype='interval[float64, right]')
IntervalIndex length...
Float64Index([nan, nan], dtype='float64')
Is the interval empty?
[False False]
以上是 Python Pandas IntervalIndex - 检查缺失值的区间是否为空 的全部内容, 来源链接: utcz.com/z/347450.html