Python Pandas - 检查元素是否属于一个 Interval
要检查某个元素是否属于某个 Interval,请使用 in 属性。首先,导入所需的库 −
import pandas as pd
创建时间间隔
interval = pd.Interval(left=0, right=10)
显示时间间隔
print("Interval...\n",interval)
检查某个元素在某个 Interval 中是否存在
print("\nThe specific element exists in the Interval? = \n",6 in interval)
示例
以下是代码
import pandas as pd # Create a time interval interval = pd.Interval(left=0, right=10) # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check for the existence of an element in an Interval print("\nThe specific element exists in the Interval? = \n",6 in interval)
输出
将生成以下代码
Interval... (0, 10] Interval length... 10 The specific element exists in the Interval? = True
广告