दिए गए लेबल के अनुरूप राइट स्लाइस बाउंड की गणना करने के लिए, index.get_slice_bound() का उपयोग करें। side पैरामीटर को right पर सेट करें।
सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:
import pandas as pd
पैंडास इंडेक्स बनाएं:
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
पैंडास इंडेक्स प्रदर्शित करें:
print("Pandas Index...\n", index)
राइट स्लाइस बाउंड प्राप्त करें। यदि "side" पैरामीटर "right" पर सेट है तो दिए गए लेबल का राइट स्लाइस बाउंड लौटाता है:
print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind='getitem'))
उदाहरण
import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
# Display the Pandas index
print("Pandas Index...\n", index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n", index.size)
# Get the right slice bound
# Returns the right slice bound of given label if "side" parameter is set to "right"
print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind='getitem'))
आउटपुट
Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64') Number of elements in the index... 7 Get the right slice bound... 3