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