इनपुट लेबल के लिए स्लाइस स्थानों की गणना करने के लिए, index.slice_locs() . का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
पांडा इंडेक्स ऑब्जेक्ट बनाएं -
index = pd.Index(list('pqrstuvwxyz'))
पांडा सूचकांक प्रदर्शित करें -
print("Pandas Index...\n",index) स्लाइस स्थान प्राप्त करें। "शुरुआत" से शुरू होने वाला लेबल है। "अंत" के साथ समाप्त होने वाला लेबल है
print("\nThe slice locations with start and stop...\n",index.slice_locs(start='q', end='v'))
उदाहरण
निम्नलिखित कोड है -
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 the slice locations
# The "start" is the label to begin with
# The "end" is the label to end with
print("\nThe slice locations with start and stop...\n",index.slice_locs(start='q', end='v')) आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Pandas Index... Index(['p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], dtype='object') Number of elements in the index... 11 The slice locations with start and stop... (1, 7)