Python Pandas – 获取IntervalIndex的右边界
要获取IntervalIndex的右边界,可以使用Pandas中的 interval.right 属性。首先,导入所需的库−
import pandas as pd
创建IntervalIndex−
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])
显示interval −
print("IntervalIndex...\n",interval)
获取右边界−
print("\nIntervalIndex的右边界...\n",interval.right)
更多Pandas文章,请阅读:Pandas教程
示例
以下是代码−
import pandas as pd
# 创建IntervalIndex
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])
# 显示interval
print("IntervalIndex...\n",interval)
# 显示interval的长度
print("\nIntervalIndex的长度...\n",interval.length)
# 检查IntervalIndex的左侧、右侧、两侧或都不封闭的类型
print("\n检查IntervalIndex的类型...\n",interval.closed)
# 获取右边界
print("\nIntervalIndex的右边界...\n",interval.right)
输出
这将显示以下输出−
IntervalIndex...
IntervalIndex([(5, 15], (10, 20], (15, 25]], dtype='interval[int64, right]')
IntervalIndex的长度...
Int64Index([10, 10, 10], dtype='int64')
检查IntervalIndex的类型...
right
IntervalIndex的右边界...
Int64Index([15, 20, 25], dtype='int64')