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

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

ইনডেক্স মান ডিসেন্ডিং (অবরোহী) ক্রমে সর্ট করতে 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 দিলে ডিসেন্ডিং অর্ডার।

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

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

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

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