अनुक्रमणिका की क्रमबद्ध प्रतिलिपि वापस करने के लिए, index.sort_values() . का उपयोग करें पंडों में विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
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')