यह निर्धारित करने के लिए कि क्या दो CategoricalIndex ऑब्जेक्ट में समान तत्व हैं, बराबर () का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
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("\nCheck both the CategoricalIndex objects for equality...\n",catIndex1.equals(catIndex2)) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# Set the categories for the categorical using the "categories" parameter
# Treat the categorical as ordered using the "ordered" parameter
# Create two CategoricalIndex objects
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"])
# Display the CategoricalIndex objects
print("CategoricalIndex1...\n",catIndex1)
print("\nCategoricalIndex2...\n",catIndex2)
# Check both the CategoricalIndex objects for equality
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