প্রদত্ত লেবেলের সাথে সঙ্গতিপূর্ণ বাম স্লাইসটি গণনা করতে, 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