কম্পিউটার টিউটোরিয়াল

পাইথন প্যান্ডাস - দুটি CategoricalIndex একই উপাদান ধারণ করছে কিনা চেক করুন

পাইথন প্যান্ডাসে 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 রিটার্ন করে।

  1. পান্ডাস ডেটাফ্রেম থেকে MultiIndex তৈরি করা

  2. পান্ডাস ডেটাফ্রেমে নতুন কলাম যোগ করা (বিদ্যমান কলাম থেকে)

  3. পাইথন পান্ডাস - অ্যারে থেকে মাল্টিইনডেক্স তৈরি করুন

  4. Python - Pandas-এ পাইপলাইন তৈরি করা