अनुक्रमणिका खोजने के लिए जहां पंडों के सूचकांक में क्रम बनाए रखने के लिए एक सरणी के रूप में पारित मूल्यों को सम्मिलित किया जाना चाहिए, index.searchsorted() का उपयोग करें विधि।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
पांडा इंडेक्स बनाना -
index = pd.Index([10, 20, 30, 40, 50])
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) Searchsorted - मानों को एक सरणी की तरह सम्मिलित करने के लिए सेट करें और सटीक अनुक्रमणिका स्थिति प्राप्त करें जहां इन मानों को रखा जाना चाहिए -
print("\nThe exact positions where the values should be placed?...\n",index.searchsorted([35, 60])) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# Creating Pandas index
index = pd.Index([10, 20, 30, 40, 50])
# 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)
# searchsorted
# set the values to insert like an array and get the exact index positions
# where these values should be placed
print("\nThe exact positions where the values should be placed?...\n",index.searchsorted([35, 60])) आउटपुट
यह निम्नलिखित आउटपुट देगा -
Pandas Index... Int64Index([10, 20, 30, 40, 50], dtype='int64') Number of elements in the index... 5 The exact positions where the values should be placed?... [3 5]