Python Pandas IntervalIndex - 检查仅在一个端点上重叠或不重叠的区间
如需查看仅在一个端点上重叠或不重叠的区间,请使用 IntervalIndex.is_overlapping 属性。
首先,导入必需的库 −
import pandas as pd
创建 IntervalIndex。由于将 "closed" 参数设置为 "left",因此这些区间在左侧闭合 −
interval = pd.interval_range(0, 8, closed='left')
显示区间 −
print("IntervalIndex...\n",interval)
检查仅在一个端点上重叠或不重叠的区间 −
print("\nDoes the Intervals that have an open endpoint overlap?\n",interval.is_overlapping)
举例
如下所示 −
import pandas as pd # Create IntervalIndex # The intervals are closed on the left-side since the "closed" parameter is set "left" interval = pd.interval_range(0, 8, closed='left') # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # Check if the Intervals that only have an open endpoint in common overlap or not print("\nDoes the Intervals that have an open endpoint overlap?\n",interval.is_overlapping)
输出
将生成以下输出 −
IntervalIndex... IntervalIndex([[0, 1), [1, 2), [2, 3), [3, 4), [4, 5), [5, 6), [6, 7), [7, 8)], dtype='interval[int64, left]') IntervalIndex length... Int64Index([1, 1, 1, 1, 1, 1, 1, 1], dtype='int64') Does the Intervals that have an open endpoint overlap? False
广告