Python Pandas - 检查 IntervalIndex 是否有重叠间隔
要检查IntervalIndex是否具有重叠间隔,请使用Intervalndex.is_overlapping属性。首先,导入所需的库-
import pandas as pd
创建间隔索引-
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])
显示间隔-
print("IntervalIndex...\n",interval)
检查间隔是否重叠-
print("\nIs the interval overlapping?\n",interval.is_overlapping)
示例
以下是代码-
import pandas as pd #创建间隔索引 interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)]) #显示间隔 print("IntervalIndex...\n",interval) #显示间隔 length print("\nIntervalIndex length...\n",interval.length) #检查间隔是否重叠 print("\nIs the interval overlapping?\n",interval.is_overlapping)输出结果
这将产生以下输出-
IntervalIndex... IntervalIndex([(10, 20], (15, 25]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([10, 10], dtype='int64') Is the interval overlapping? True