কম্পিউটার

Python Pandas - সূচক দ্বারা নির্বাচিত মানগুলির একটি নতুন সূচক ফেরত দিন


সূচক দ্বারা নির্বাচিত মানগুলির একটি নতুন সূচক ফেরত দিতে, index.take() ব্যবহার করুন পান্ডাসে পদ্ধতি। প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন -

import pandas as pd

পান্ডাস সূচক তৈরি করা হচ্ছে -

index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')

পান্ডাস সূচক প্রদর্শন করুন -

print("Pandas Index...\n",index)

সূচক দ্বারা নির্বাচিত মানগুলির একটি নতুন সূচক পাওয়া −

print("\nA new Index of the values selected by the indices...\n",index.take([1,2]))

উদাহরণ

নিম্নলিখিত কোড -

import pandas as pd

# Creating Pandas index
index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')

# 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)

# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)

# Getting a new index of the values selected by indices
print("\nA new Index of the values selected by the indices...\n",index.take([1,2]))

আউটপুট

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

তৈরি করবে
Pandas Index...
Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], dtype='object', name='Products')

Number of elements in the index...
5

The dtype object...
object

A new Index of the values selected by the indices...
Index(['Accessories', 'Decor'], dtype='object', name='Products')

  1. Python Pandas - সূচকে অনন্য মান ফেরত দিন

  2. Python Pandas - মাস্কের সাথে সেট করা মানগুলির একটি নতুন সূচক ফেরত দিন

  3. Python - পান্ডাস সূচকের সর্বোচ্চ মান ফেরত দিন

  4. পাইথন - পান্ডাস সূচকের সর্বনিম্ন মান ফেরত দিন