इंडेक्स द्वारा चुने गए मानों का एक नया इंडेक्स वापस करने के लिए, index.take() . का उपयोग करें पंडों में विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
पांडा इंडेक्स बनाना -
index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) सूचकांकों द्वारा चयनित मूल्यों का एक नया सूचकांक प्राप्त करना -
print("\nA new Index of the values selected by the indices...\n",index.take([1,2])) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# Creating Pandas index
index = pd.Index(['Electronics','Accessories','Decor', 'Books', 'Toys'], name ='Products')
# 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)
# Getting a new index of the values selected by indices
print("\nA new Index of the values selected by the indices...\n",index.take([1,2])) आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Pandas Index... Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], dtype='object', name='Products') Number of elements in the index... 5 The dtype object... object A new Index of the values selected by the indices... Index(['Accessories', 'Decor'], dtype='object', name='Products')