পান্ডাস সূচকে শৃঙ্খলা বজায় রাখার জন্য উপাদানগুলি যেখানে ঢোকানো উচিত সূচকগুলি সন্ধান করতে, index.searchsorted() ব্যবহার করুন পদ্ধতি।
প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
পান্ডাস সূচক তৈরি করা হচ্ছে -
index = pd.Index([10, 20, 30, 40, 50])
পান্ডাস সূচক প্রদর্শন করুন -
print("Pandas Index...\n",index) অনুসন্ধান বাছাই করা:সন্নিবেশ করার জন্য মান সেট করুন এবং সঠিক সূচকের অবস্থানটি পান যেখানে এটি স্থাপন করা উচিত -
print("\nThe exact positions where the element should be placed?...\n",index.searchsorted(45)) উদাহরণ
নিম্নলিখিত কোড -
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 value to insert and get the exact index position where it should be placed
print("\nThe exact positions where the element should be placed?...\n",index.searchsorted(45)) আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেPandas Index... Int64Index([10, 20, 30, 40, 50], dtype='int64') Number of elements in the index... 5 The exact positions where the element should be placed?... 4