কম্পিউটার

Python Pandas CategoricalIndex - বিভাগগুলির একটি আদেশকৃত সম্পর্ক আছে কিনা তা পরীক্ষা করুন


বিভাগগুলির একটি আদেশকৃত সম্পর্ক আছে কিনা তা পরীক্ষা করতে, অর্ডার করা ব্যবহার করুন৷ CategoricalIndex এর সম্পত্তি।

প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -

import pandas as pd

"বিভাগগুলি" প্যারামিটার ব্যবহার করে শ্রেণীবদ্ধের জন্য বিভাগগুলি সেট করুন। "অর্ডার করা" পরামিতি −

ব্যবহার করে শ্রেণীবদ্ধকে ক্রমানুসারে বিবেচনা করুন
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

শ্রেণীগত সূচক প্রদর্শন করুন -

print("Categorical Index...\n",catIndex)

বিভাগগুলি পান
print("\nDisplayingCategories from CategoricalIndex...\n",catIndex.categories)

আদেশকৃত সম্পর্কের জন্য বিভাগগুলি পরীক্ষা করুন −

print("\nDoes categories have ordered relationship...\n",catIndex.ordered)

উদাহরণ

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

import pandas as pd

# CategoricalIndex can only take on a limited, and usually fixed, number of possible values
# Set the categories for the categorical using the "categories" parameter
# Treat the categorical as ordered using the "ordered" parameter
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

# Display the Categorical Index
print("Categorical Index...\n",catIndex)

# Get the categories
print("\nDisplayingCategories from CategoricalIndex...\n",catIndex.categories)

# Check categories for ordered relationship
print("\nDoes categories have ordered relationship...\n",catIndex.ordered)

আউটপুট

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

তৈরি করবে
Categorical Index...
CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category')

DisplayingCategories from CategoricalIndex...
Index(['p', 'q', 'r', 's'], dtype='object')

Does categories have ordered relationship...
True

  1. Python Pandas - পিরিয়ড অবজেক্ট থেকে বছরটি একটি লিপ ইয়ার কিনা তা পরীক্ষা করুন

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

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

  4. Python Pandas - দুটি ইনডেক্স অবজেক্টের একই ধরনের অবজেক্ট অ্যাট্রিবিউট এবং প্রকার আছে কিনা তা পরীক্ষা করুন