কম্পিউটার

Python Pandas - ক্যাটেগরিক্যাল ইনডেক্সের শ্রেণীবিভাগকে ক্রমবিহীনভাবে সেট করুন


CategoricalIndex-এর শ্রেণীবিভাগকে ক্রমবিহীন অবস্থায় সেট করতে, as_unordered() ব্যবহার করুন পান্ডাসে পদ্ধতি।

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

import pandas as pd

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

হিসাবে বিবেচনা করুন
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

বিভাগগুলিকে ক্রমবিহীন −

সেট করুন৷
print("\nCategoricalIndex unordered...\n", catIndex.as_unordered())

উদাহরণ

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

import pandas as pd

# Set the categories for the categorical using the "categories" parameter
# Treat the categorical as ordered using the "ordered" parameter with value True
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

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

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

# Set the categories to be unordered
print("\nCategoricalIndex unordered...\n", catIndex.as_unordered())

আউটপুট

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

তৈরি করবে
CategoricalIndex...
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')

CategoricalIndex unordered...
CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=False, dtype='category')

  1. Python Pandas - সূচকের নাম সেট করুন

  2. Python Pandas - সূচকের স্থানান্তর ফিরিয়ে দিন

  3. Python Pandas - মাস্কের সাথে সেট করা মানগুলির একটি নতুন সূচক ফেরত দিন

  4. Python - সেটে পান্ডা টাইপকাস্ট করা হচ্ছে