Để có được giới hạn phù hợp cho IntervalIndex, hãy sử dụng khoảng thời gian.right tài sản ở Pandas. Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo IntervalIndex -
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])
Hiển thị khoảng thời gian -
print("IntervalIndex...\n",interval) Có được ràng buộc phù hợp -
print("\nThe right bound for the IntervalIndex...\n",interval.right)
Ví dụ
Sau đây là mã -
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) Đầu ra
Điều này sẽ tạo ra kết quả sau -
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')