Python Pandas - 检查 IntervalIndex 中是否有重叠的间隔


要检查 IntervalIndex 中是否有重叠的间隔,请使用 Intervalndex.is_overlapping 属性。首先,导入所需的库 -

import pandas as pd

创建 IntervalIndex -

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

# Create IntervalIndex
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])

# Display the interval
print("IntervalIndex...\n",interval)

# Display the interval length
print("\nIntervalIndex length...\n",interval.length)

# Check if the interval is overlapping or not
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

更新时间:18-Oct-2021

316 次浏览

开启您的 职业生涯

完成课程获得认证

开始
广告