পাইথন প্যান্ডাসে equals() মেথড ব্যবহার করে দুটি CategoricalIndex অবজেক্ট একই উপাদান, ক্যাটেগরি এবং অর্ডার ধারণ করছে কিনা তা চেক করা যায়।
প্রয়োজনীয় লাইব্রেরি ইম্পোর্ট করুন
import pandas as pd
দুটি CategoricalIndex তৈরি করুন
ক্যাটেগরি: ['p', 'q', 'r', 's'], অর্ডার্ড: True
catIndex1 = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
catIndex2 = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
দুটি CategoricalIndex সমান কিনা চেক করুন
print("\nCheck both the CategoricalIndex objects for equality...\n", catIndex1.equals(catIndex2))
সম্পূর্ণ উদাহরণ
import pandas as pd
# দুটি CategoricalIndex তৈরি
catIndex1 = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
catIndex2 = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])
# CategoricalIndex অবজেক্টগুলো প্রদর্শন
print("CategoricalIndex1...\n", catIndex1)
print("\nCategoricalIndex2...\n", catIndex2)
# সমানতা চেক
print("\nCheck both the CategoricalIndex objects for equality...\n", catIndex1.equals(catIndex2))
আউটপুট
CategoricalIndex1... CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category') CategoricalIndex2... CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category') Check both the CategoricalIndex objects for equality... True
ব্যাখ্যা: দুটি CategoricalIndex-এ একই মান, একই ক্যাটেগরি এবং একই অর্ডার থাকায় equals() True রিটার্ন করে।