কম্পিউটার

Python Pandas - প্রদত্ত লেবেলের সাথে মিলে যাওয়া ডান স্লাইসটি গণনা করুন


প্রদত্ত লেবেলের সাথে সামঞ্জস্যপূর্ণ সঠিক স্লাইস বাউন্ড গণনা করতে, 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 right slice bound...\n",index.get_slice_bound(30, side='right', 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 right slice bound
# Returns the right slice bound of given label if "side" parameter is set to "right"
print("\nGet the right slice bound...\n", index.get_slice_bound(30, side='right', kind ='getitem'))

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
Pandas Index...
Int64Index([10, 20, 30, 40, 50, 60, 70], dtype='int64')

Number of elements in the index...
7

Get the right slice bound...
3

  1. পাইথন - পান্ডাস সূচকটি অবজেক্ট dটাইপের কিনা তা পরীক্ষা করুন

  2. Python - পান্ডাস সূচক একটি ভাসমান প্রকার কিনা তা পরীক্ষা করুন

  3. Python Pandas - একটি সূচী হিসাবে IntervalArray-এ প্রতিটি ব্যবধানের ডান প্রান্তের পয়েন্ট ফেরত দিন

  4. Python Pandas - ব্যবধানের জন্য সঠিক আবদ্ধ পান