दिए गए लेबल से संबंधित सही स्लाइस बाउंड की गणना करने के लिए, index.get_slice_bound() का उपयोग करें . पक्ष सेट करें पैरामीटर दाएं ।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
पांडा इंडेक्स बनाना -
index = pd.Index([10, 20, 30, 40, 50, 60, 70])
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) सही टुकड़ा बाध्य हो जाओ। यदि "साइड" पैरामीटर "दाएं" पर सेट है, तो दिए गए लेबल का दायां टुकड़ा बाउंड लौटाता है -
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