কম্পিউটার

পাইথন - পান্ডাস সূচকে সুনির্দিষ্ট ডেটা আছে কিনা তা পরীক্ষা করুন


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

import pandas as pd

বিভাগ হিসাবে সেট করা টাইপ সহ পান্ডাস সূচক তৈরি করা হচ্ছে astype() ব্যবহার করে পদ্ধতি -

index = pd.Index(["Electronics","Accessories","Furniture"]).astype("category")

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

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

সূচীতে শ্রেণীগত তথ্য আছে কিনা তা পরীক্ষা করুন −

print("\nDoes Index holds categorical data?\n",index.is_categorical())

উদাহরণ

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

import pandas as pd

# Creating Pandas index
index = pd.Index(["Electronics","Accessories","Furniture"]).astype("category")

# 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...\n",index.dtype)

# check whether index holds categorical data
print("\nDoes Index holds categorical data?\n",index.is_categorical())

আউটপুট

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

তৈরি করবে
Pandas Index...
CategoricalIndex(['Electronics', 'Accessories', 'Furniture'], categories=['Accessories', 'Electronics', 'Furniture'], ordered=False, dtype='category')

Number of elements in the index...
3

The dtype...
category

Does Index holds categorical data?
True

  1. Python Pandas - পান্ডাস সূচক ইন্টারভাল অবজেক্ট ধারণ করে কিনা তা পরীক্ষা করুন

  2. পাইথন - পান্ডাস সূচকে শুধুমাত্র পূর্ণসংখ্যা রয়েছে কিনা তা পরীক্ষা করুন

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

  4. পাইথন - পান্ডাস সূচকে শুধুমাত্র বুলিয়ান রয়েছে কিনা তা পরীক্ষা করুন