Python Pandas - 从左侧封闭时检查一个区间是否为空
要检查从左侧封闭时一个区间是否为空,使用 interval.is_empty 属性。首先,导入所需的库 −
import pandas as pd
从左侧封闭的区间。使用值“left”设置“closed”参数,设置区间
interval = pd.Interval(0, 0, closed='left')
显示区间
print("Interval...\n",interval)
检查区间是否为空
print("\nIs Interval empty? \n",interval.is_empty)
示例
以下为代码
import pandas as pd # interval closed from the left # Interval set using the "closed" parameter with value "left" interval = pd.Interval(0, 0, closed='left') # 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
广告