Python Pandas - 检查一个区间是否为空
要检查一个区间是否为空,可使用 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 # Create an interval interval = pd.Interval(0, 0, closed='right') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check whether interval is empty print("\nIs Interval empty? \n",interval.is_empty)
输出
这会生成以下代码
Interval... (0, 0] Interval length... 0 Is Interval empty? True
广告