কম্পিউটার

Python Pandas - একটি ইতিমধ্যে তৈরি সূচক বস্তুর জন্য সূচী নাম সেট করুন


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

import pandas as pd

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

index = pd.Index(["Electronics", "Mobile Phones", "Accessories", "Home Decor", "Books"])

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

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

সূচকের নাম সেট করুন −

print("\nSet the index name...\n",index.set_names('Products'))

উদাহরণ

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

import pandas as pd

# Creating Pandas index
index = pd.Index(["Electronics", "Mobile Phones", "Accessories", "Home Decor", "Books"])

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

# set the name of index
print("\nSet the index name...\n",index.set_names('Products'))

আউটপুট

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

তৈরি করবে
Pandas Index...
Index(['Electronics', 'Mobile Phones', 'Accessories', 'Home Decor', 'Books'], dtype='object')

Number of elements in the index...
5

The dtype object...
object

Set the index name...
Index(['Electronics', 'Mobile Phones', 'Accessories', 'Home Decor', 'Books'], dtype='object', name='Products')

  1. Python Pandas - একটি সূচকের উপাদানগুলি পুনরাবৃত্তি করুন

  2. Python Pandas - পরিবর্তন সূচক নাম

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

  4. পাইথন পান্ডাসে কলামের নাম থেকে কলাম সূচক কীভাবে পাবেন?