একটি সোর্টেড প্যান্ডাস Index-এ একাধিক মান কোথায় ইনসার্ট করলে অর্ডার বজায় থাকবে, তা জানতে index.searchsorted([values]) মেথড ব্যবহার করুন। এটি প্রতিটি মানের জন্য ইনসারশন পজিশন রিটার্ন করে।
প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন
import pandas as pd
প্যান্ডাস ইনডেক্স তৈরি করুন (সোর্টেড হতে হবে)
index = pd.Index([10, 20, 30, 40, 50])
ইনডেক্স প্রদর্শন করুন
print("Pandas Index...\n", index)
ইনসারশন পজিশন খুঁজুন (অ্যারে ইনপুট)
print("\nThe exact positions where the values should be placed?...\n", index.searchsorted([35, 60]))
সম্পূর্ণ উদাহরণ
import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50])
# 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)
# searchsorted
# set the values to insert like an array and get the exact index positions
# where these values should be placed
print("\nThe exact positions where the values should be placed?...\n", index.searchsorted([35, 60]))
আউটপুট
Pandas Index... Int64Index([10, 20, 30, 40, 50], dtype='int64')
Number of elements in the index... 5
The exact positions where the values should be placed?... [3 5]
ব্যাখ্যা: ৩৫ ইনসার্ট করলে ৩ নম্বর পজিশনে (৩০ এবং ৪০-এর মাঝে), ৬০ ইনসার্ট করলে ৫ নম্বর পজিশনে (৫০-এর পরে)। ইনডেক্স সোর্টেড থাকতে হয়; অন্যথায় ফলাফল অনিশ্চিত।