पंडों में अनुरोधित लेबल के लिए पूर्णांक स्थान प्राप्त करने के लिए, index.get_loc() . का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
पांडा इंडेक्स ऑब्जेक्ट बनाएं -
index = pd.Index(list('pqrstuvwxyz'))
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) दिए गए इंडेक्स से पूर्णांक स्थान प्राप्त करें -
print("\nDisplay integer location from given index...\n",index.get_loc('w'))
print("\nDisplay integer location from given index...\n",index.get_loc('z')) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# create Pandas index object
index = pd.Index(list('pqrstuvwxyz'))
# 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)
# get integer location from the given index
print("\nDisplay integer location from given index...\n",index.get_loc('w'))
print("\nDisplay integer location from given index...\n",index.get_loc('z')) आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Pandas Index... Index(['p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], dtype='object') Number of elements in the index... 11 Display integer location from given index... 7 Display integer location from given index... 10