কম্পিউটার

Python Pandas CategoricalIndex - এই ক্যাটাগরিকালের বিভাগ কোডগুলি পান


এই ক্যাটাগরিকালের বিভাগ কোডগুলি পেতে, কোডগুলি ব্যবহার করুন৷ CategoricalIndex এর সম্পত্তি পান্ডায় প্রথমে, প্রয়োজনীয় লাইব্রেরিগুলি আমদানি করুন -

import pandas as pd

CategoricalIndex শুধুমাত্র একটি সীমিত, এবং সাধারণত স্থির, সম্ভাব্য মানের সংখ্যা (বিভাগ) নিতে পারে। "বিভাগগুলি" প্যারামিটার ব্যবহার করে শ্রেণীবদ্ধের জন্য বিভাগগুলি সেট করুন। "অর্ডার করা" পরামিতি ব্যবহার করে নির্দেশিত হিসাবে শ্রেণীগত আচরণ করুন। কোড হল পূর্ণসংখ্যার একটি অ্যারে যা ক্যাটাগরি অ্যারের প্রকৃত মানগুলির অবস্থান −

catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

শ্রেণীগত সূচক প্রদর্শন করুন -

print("Categorical Index...\n",catIndex)

বিভাগ কোড পান -

print("\nCategory codes from CategoricalIndex...\n",catIndex.codes)

উদাহরণ

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

import pandas as pd

# CategoricalIndex can only take on a limited, and usually fixed, number of possible values
# Set the categories for the categorical using the "categories" parameter
# Treat the categorical as ordered using the "ordered" parameter
# Codes are an array of integers which are the positions of the actual values in the categories array.
catIndex = pd.CategoricalIndex(["p", "q", "r", "s","p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])

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

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

# Get the category codes
print("\nCategory codes from CategoricalIndex...\n",catIndex.codes)

আউটপুট

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

তৈরি করবে
Categorical Index...
CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', 'q', 'r', 's'], ordered=True, dtype='category')

DisplayingCategories from CategoricalIndex...
Index(['p', 'q', 'r', 's'], dtype='object')

Category codes from CategoricalIndex...
[0 1 2 3 0 1 2 3]

  1. Python Pandas - পিরিয়ডের দ্বিতীয় উপাদান পান

  2. Python Pandas - বছরের উপাদানের মাস পান

  3. Python Pandas - পিরিয়ডের ঘন্টা উপাদানের মিনিট পান

  4. Python Pandas - সময়কালের দিনের উপাদানের ঘন্টা পান