ইনডেক্স মান ডিসেন্ডিং (অবরোহী) ক্রমে সর্ট করতে index.sort_values(ascending=False) ব্যবহার করুন। এটি নতুন সর্টেড ইনডেক্স রিটার্ন করে, মূল ইনডেক্স অপরিবর্তিত থাকে।
প্রয়োজনীয় লাইব্রেরি ইমপোর্ট করুন
import pandas as pd
প্যান্ডাস ইনডেক্স তৈরি করুন
index = pd.Index([50, 10, 70, 95, 110, 90, 30])
ইনডেক্স প্রদর্শন করুন
print("Pandas Index...\n", index)
ডিসেন্ডিং অর্ডারে সর্ট করুন
print("\nSort the index values in descending order...\n", index.sort_values(ascending=False))
সম্পূর্ণ উদাহরণ
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
# To sort values in Descending order, set the "ascending" parameter to "False"
print("\nSort the index values in descending order...\n", index.sort_values(ascending=False))
আউটপুট
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 in descending order... Int64Index([110, 95, 90, 70, 50, 30, 10], dtype='int64')
টিপস: ascending=True (ডিফল্ট) দিলে অ্যাসেন্ডিং, ascending=False দিলে ডিসেন্ডিং অর্ডার।