Pandas में वर्तमान अंतराल सरणी के समान लेकिन निर्दिष्ट साइड पर बंद एक IntervalArray लौटाने के लिए, set_closed() मेथड का उपयोग both पैरामीटर के साथ करें।
आवश्यक लाइब्रेरी इम्पोर्ट करें
import pandas as pd
IntervalArray बनाएं
index = pd.arrays.IntervalArray.from_breaks(range(6))
अंतराल प्रदर्शित करें
print("IntervalIndex...\n", index)
निर्दिष्ट साइड पर बंद IntervalArray लौटाएं
print("\nResult...", index.set_closed('both'))
पूरा उदाहरण
import pandas as pd
# IntervalArray बनाएं
index = pd.arrays.IntervalArray.from_breaks(range(6))
# अंतराल प्रदर्शित करें
print("IntervalIndex...\n", index)
# अंतराल लंबाई प्रदर्शित करें
print("\nIntervalIndex length...\n", index.length)
# बायां बाउंड
print("\nThe left bound for the IntervalIndex...\n", index.left)
# दायां बाउंड
print("\nThe right bound for the IntervalIndex...\n", index.right)
# निर्दिष्ट साइड "both" पर बंद IntervalArray लौटाएं
print("\nResult...", index.set_closed('both'))
आउटपुट
IntervalIndex... [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right]
IntervalIndex length... Int64Index([1, 1, 1, 1, 1], dtype='int64')
The left bound for the IntervalIndex... Int64Index([0, 1, 2, 3, 4], dtype='int64')
The right bound for the IntervalIndex... Int64Index([1, 2, 3, 4, 5], dtype='int64')
Result... [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] Length: 5, dtype: interval[int64, both]
व्याख्या: set_closed('both') अंतराल के दोनों सिरों को बंद कर देता है (समावेशी)।