Python Pandas - 获取 IntervalIndex 的右边界


若要获取 IntervalIndex 的右边界,请在 Pandas 中使用 interval.right 属性。首先,导入所需的库 −

import pandas as pd

创建 IntervalIndex −

interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])

显示区间 −

print("IntervalIndex...\n",interval)

获取右边界 −

print("\nThe right bound for the IntervalIndex...\n",interval.right)

示例

以下是代码 −

import pandas as pd

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

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

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

# Check whether the IntervalIndex is closed on the left-side, right-side, both or neither
print("\nChecking for the type of IntervalIndex...\n",interval.closed)

# Get the right bound
print("\nThe right bound for the IntervalIndex...\n",interval.right)

输出

将产生以下输出 −

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

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

Checking for the type of IntervalIndex...
right

The right bound for the IntervalIndex...
Int64Index([15, 20, 25], dtype='int64')

更新于: 18-Oct-2021

106 浏览量

开启你的 职业生涯

通过完成课程获取认证

开始吧
广告