पैंडास इंडेक्स में क्रम बनाए रखने के लिए मानों को इन्सर्ट करने के इंडेक्स खोजने के लिए, 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]