Python Pandas - 获取 IntervalIndex 的左边界
要获得IntervalIndex的左边界,请使用Pandas中的interval.left属性。首先,导入所需的库-
import pandas as pd
创建间隔索引-
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])
显示间隔-
print("IntervalIndex...\n",interval)
获取左边界-
print("\nThe left bound for the IntervalIndex...\n",interval.left)
示例
以下是代码-
import pandas as pd #创建间隔索引 interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25]) #显示间隔 print("IntervalIndex...\n",interval) #显示间隔 length print("\nIntervalIndex length...\n",interval.length) #检查IntervalIndex是否在左侧,右侧,两者都关闭或都不关闭 print("\nChecking for the type of IntervalIndex...\n",interval.closed) #获取左边界 print("\nThe left bound for the IntervalIndex...\n",interval.left)输出结果
这将产生以下输出-
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 left bound for the IntervalIndex... Int64Index([5, 10, 15], dtype='int64')