পান্ডাস ইনডেক্স অবজেক্টের slice_locs() মেথড ব্যবহার করে দেওয়া লেবেল রেঞ্জের স্লাইস লোকেশন (স্টার্ট ও স্টপ পজিশন) বের করা যায়।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট
import pandas as pd
পান্ডাস ইনডেক্স অবজেক্ট তৈরি
index = pd.Index(list('pqrstuvwxyz'))
ইনডেক্স প্রদর্শন
print("Pandas Index...\n", index)
স্লাইস লোকেশন বের করা
start = শুরু লেবেল, end = শেষ লেবেল (ইনক্লুসিভ)।
print("\nThe slice locations with start and stop...\n", index.slice_locs(start='q', end='v'))
সম্পূর্ণ উদাহরণ কোড
import pandas as pd
index = pd.Index(list('pqrstuvwxyz'))
print("Pandas Index...\n", index)
print("\nNumber of elements in the index...\n", index.size)
print("\nThe slice locations with start and stop...\n", index.slice_locs(start='q', end='v'))
আউটপুট
Pandas Index...
Index(['p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], dtype='object')
Number of elements in the index...
11
The slice locations with start and stop...
(1, 7)
ব্যাখ্যা
রিটার্ন টাপল (start_loc, end_loc) যেখানে end_loc এক্সক্লুসিভ। উদাহরণে 'q' ইনডেক্স ১, 'v' ইনডেক্স ৬ → স্লাইস slice(1, 7) অর্থাৎ পজিশন ১ থেকে ৬ পর্যন্ত (৭ এক্সক্লুসিভ)।