एक इंटरवलएरे को वर्तमान के समान लेकिन निर्दिष्ट पक्ष पर बंद करने के लिए, set_closed() का उपयोग करें पैरामीटर के साथ विधि दोनों . के रूप में सेट है ।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
इंटरवलएरे बनाएं -
index = pd.arrays.IntervalArray.from_breaks(range(6))
अंतराल प्रदर्शित करें -
print("IntervalIndex...\n",index) एक इंटरवलएरे को वर्तमान के समान लौटाएं लेकिन निर्दिष्ट पक्ष पर बंद कर दें यानी "दोनों" यहां -
print("\nResult...",index.set_closed('both'))
उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# Create IntervalArray
index = pd.arrays.IntervalArray.from_breaks(range(6))
# Display the interval
print("IntervalIndex...\n",index)
# Display the interval length
print("\nIntervalIndex length...\n",index.length)
# the left bound
print("\nThe left bound for the IntervalIndex...\n",index.left)
# the right bound
print("\nThe right bound for the IntervalIndex...\n",index.right)
# Return an IntervalArray identical to the current one but closed on specified
# side i.e. "both" here
print("\nResult...",index.set_closed('both')) आउटपुट
यह निम्नलिखित आउटपुट देगा -
IntervalIndex... <IntervalArray> [(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... <IntervalArray> [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] Length: 5, dtype: interval[int64, both]