ক্যাটেগরিক্যাল ইনডেক্সের বিভাগগুলি অর্ডার করার জন্য সেট করতে, as_ordered() ব্যবহার করুন পান্ডাসে পদ্ধতি।
প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -
import pandas as pd
"বিভাগ" পরামিতি −
ব্যবহার করে ক্যাটাগরিকালের জন্য বিভাগগুলি সেট করুনcatIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], categories=["p", "q", "r", "s"])
−
বিভাগগুলি পানprint("\nDisplaying Categories from CategoricalIndex...\n",catIndex.categories)
অর্ডার করার জন্য বিভাগগুলি সেট করুন −
print("\nCategoricalIndex ordered...\n", catIndex.as_ordered()) উদাহরণ
নিম্নলিখিত কোড -
import pandas as pd
# Set the categories for the categorical using the "categories" parameter
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], 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 ordered
print("\nCategoricalIndex ordered...\n", catIndex.as_ordered()) আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেCategoricalIndex... CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=False, dtype='category') Displaying Categories from CategoricalIndex... Index(['p', 'q', 'r', 's'], dtype='object') CategoricalIndex ordered... CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category')