दिए गए लेबल से संबंधित बाएं स्लाइस बाउंड की गणना करने के लिए, 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 left slice bound...\n",index.get_slice_bound(30, side='left', 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 left slice bound
# Returns the left slice bound of given label if "side" parameter is set to "left"
print("\nGet the left slice bound...\n", index.get_slice_bound(30, side='left', kind ='getitem')) आउटपुट
यह निम्नलिखित आउटपुट देगा -
Pandas Index... Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64') Number of elements in the index... 7 Get the left slice bound... 2