Python Pandas - 如果从两侧关闭,检查间隔是否为空
要检查从两侧关闭的区间是否为空,请使用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 #intervalclosedfromthebothsides # Interval set using the "closed" 带值的参数 "both" interval = pd.Interval(0, 0, closed='both') #displaytheinterval print("Interval...\n",interval) #displaytheinterval length print("\nInterval length...\n",interval.length) #checkwhetherintervalisemptywhenitisclosedfrombothsides #AnIntervalthatcontainsasinglepointisnotemptyi.e.Falseisreturned print("\nIs Interval empty? \n",interval.is_empty)输出结果
这将产生以下代码
Interval... [0, 0] Interval length... 0 Is Interval empty? False