यदि कोई लेबल कई अंतरालों में है तो सभी प्रासंगिक अंतराल के स्थान प्राप्त करने के लिए, get_loc() का उपयोग करें पंडों में विधि।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
दो इंटरवल ऑब्जेक्ट बनाएं। "बंद" पैरामीटर का उपयोग करके "दोनों" मान के साथ बंद अंतराल सेट करें
interval1 = pd.Interval(50, 75) interval2 = pd.Interval(75, 90) interval3 = pd.Interval(50, 90)
तीन अंतरालों से इंटरवलइंडेक्स बनाएं -
index = pd.IntervalIndex([interval1, interval2, interval3])
यदि कोई लेबल कई अंतरालों में है तो सभी प्रासंगिक अंतराल के स्थान प्राप्त करें -
print("\nGet the locations of all the relevant interval...\n",index.get_loc(65)) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# Create two Interval objects
# Closed intervals set using the "closed" parameter with value "both"
interval1 = pd.Interval(50, 75)
interval2 = pd.Interval(75, 90)
interval3 = pd.Interval(50, 90)
# display the intervals
print("Interval1...\n",interval1)
print("Interval2...\n",interval2)
print("Interval3...\n",interval3)
# Create IntervalIndex from the three intervals
index = pd.IntervalIndex([interval1, interval2, interval3])
# Get the locations of all the relevant interval if a label is in several intervals
print("\nGet the locations of all the relevant interval...\n",index.get_loc(65)) आउटपुट
यह निम्नलिखित आउटपुट देगा -
Interval1... (50, 75] Interval2... (75, 90] Interval3... (50, 90] Get the locations of all the relevant interval... [ True False True]