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

পাইথন প্যান্ডাস - ইনডেক্সের সর্টেড কপি রিটার্ন করুন (অ্যাসেন্ডিং)

ইনডেক্স মান অ্যাসেন্ডিং (আরোহী) ক্রমে সর্ট করতে index.sort_values() ব্যবহার করুন। এটি ডিফল্ট আচরণ, তাই ascending=True লিখতে হয় না।

প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন

import pandas as pd

প্যান্ডাস ইনডেক্স তৈরি করুন

index = pd.Index([50, 10, 70, 95, 110, 90, 30])

ইনডেক্স প্রদর্শন করুন

print("Pandas Index...\n", index)

অ্যাসেন্ডিং অর্ডারে সর্ট করুন

print("\nSort the index values...\n", index.sort_values())

সম্পূর্ণ উদাহরণ

import pandas as pd

# Creating Pandas index
index = pd.Index([50, 10, 70, 95, 110, 90, 30])

# Display the Pandas index
print("Pandas Index...\n", index)

# Return the number of elements in the Index
print("\nNumber of elements in the index...\n", index.size)

# Return the dtype of the data
print("\nThe dtype object...\n", index.dtype)

# Sort index values
# By default, sorts in Ascending order
print("\nSort the index values...\n", index.sort_values())

আউটপুট

Pandas Index... Int64Index([50, 10, 70, 95, 110, 90, 30], dtype='int64')
Number of elements in the index... 7
The dtype object... int64
Sort the index values... Int64Index([10, 30, 50, 70, 90, 95, 110], dtype='int64')

নোট: এটি নতুন ইনডেক্স রিটার্ন করে; মূল index অপরিবর্তিত থাকে। ইন-প্লেস সর্টিংয়ের জন্য index.sort_values(inplace=True) ব্যবহার করা যায় (প্যান্ডাস ২.০+ এ)।

  1. পাইথন প্যান্ডাস - ইন্ডেক্সের মাধ্যমে নির্বাচিত মানগুলোর নতুন ইন্ডেক্স ফেরত দেওয়া

  2. পাইথন - প্যান্ডাস ইন্ডেক্সের সর্বাধিক মান ফেরত দিন

  3. পাইথন - প্যান্ডাস ইন্ডেক্সের ন্যূনতম মান ফেরত দিন

  4. পাইথন প্যান্ডাস - IntervalArray-এ প্রতিটি ইন্টারভালের মিডপয়েন্ট Index হিসেবে ফেরত দিন