要检查 Interval 是否为空,请使用interval.is_empty 属性。首先,导入所需的库 -
import pandas as pd
创建间隔
interval = pd.Interval(0, 0, closed='right')
显示间隔
print("Interval...\n",interval)
检查间隔是否为空
print("\nIs Interval empty? \n",interval.is_empty)
以下是代码
import pandas as pd # 创建间隔 interval = pd.Interval(0, 0, closed='right') # 显示间隔 print("Interval...\n",interval) # 显示间隔 length print("\nInterval length...\n",interval.length) # 检查间隔是否为空 print("\nIs Interval empty? \n",interval.is_empty)输出结果
这将产生以下代码
Interval... (0, 0] Interval length... 0 Is Interval empty? True