Python Pandas - 获取 IntervalIndex 的左边界
要在 Python 中获取 IntervalIndex 的左边界,请使用 Pandas 中的 interval.left 属性。首先,导入所需的库 −
import pandas as pd
创建 IntervalIndex −
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 # 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 left bound 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')
广告