要检查从两侧关闭的区间是否为空,请使用interval.is_empty 属性。首先,导入所需的库 -
import pandas as pd
间隔从两侧关闭。使用值为“both”的“closed”参数设置的间隔
interval = pd.Interval(0, 0, closed='both')
显示间隔
print("Interval...\n",interval)
从两边关闭时检查interval是否为空。包含单个点的区间不为空,即返回 False
print("\nIs Interval empty? \n",interval.is_empty)
以下是代码
import pandas as pd # interval closed from the both sides # Interval set using the "closed" 带值的参数 "both" interval = pd.Interval(0, 0, closed='both') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check whether interval is empty when it is closed from both sides # An Interval that contains a single point is not empty i.e. False is returned print("\nIs Interval empty? \n",interval.is_empty)输出结果
这将产生以下代码
Interval... [0, 0] Interval length... 0 Is Interval empty? False