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

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("\n间隔是否重叠?\n",interval.is_overlapping)

更多Pandas文章,请阅读:Pandas教程

示例

以下是代码 –

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("\n间隔是否重叠?\n",interval.is_overlapping)

输出

这将产生以下输出 –

IntervalIndex...
IntervalIndex([(10, 20], (15, 25]], dtype='interval[int64, right]')

IntervalIndex length...
Int64Index([10, 10], dtype='int64')

间隔是否重叠?
True

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程