পাইথন প্যান্ডাসে ordered প্রোপার্টি ব্যবহার করে CategoricalIndex-এ ক্যাটেগরিগুলোর মধ্যে অর্ডার্ড রিলেশন (ক্রম) আছে কিনা তা চেক করা যায়। এটি বুলিয়ান মান রিটার্ন করে।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন
import pandas as pd
CategoricalIndex তৈরি করুন (অর্ডার্ড)
ক্যাটেগরি: ['p', 'q', 'r', 's'], অর্ডার্ড: True
catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
Categorical Index প্রদর্শন করুন
print("Categorical Index...\n", catIndex)
ক্যাটেগরি প্রদর্শন করুন
print("\nDisplaying Categories from CategoricalIndex...\n", catIndex.categories)
অর্ডার্ড রিলেশন চেক করুন
print("\nDoes categories have ordered relationship...\n", catIndex.ordered)
সম্পূর্ণ উদাহরণ
import pandas as pd
# CategoricalIndex তৈরি (অর্ডার্ড)
catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
# Categorical Index প্রদর্শন
print("Categorical Index...\n", catIndex)
# ক্যাটেগরি প্রদর্শন
print("\nDisplaying Categories from CategoricalIndex...\n", catIndex.categories)
# অর্ডার্ড রিলেশন চেক
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') Displaying Categories from CategoricalIndex... Index(['p', 'q', 'r', 's'], dtype='object') Does categories have ordered relationship... True
ব্যাখ্যা: CategoricalIndex তৈরি করার সময় ordered=True দেওয়া থাকায় ordered প্রোপার্টি True রিটার্ন করে।