Pandas में एलिमेंट-वाइज जांचने के लिए कि IntervalIndex में अंतराल मान समाहित करते हैं या नहीं, IntervalIndex.contains() मेथड का उपयोग करें।
आवश्यक लाइब्रेरी इम्पोर्ट करें
import pandas as pd
IntervalIndex बनाएं
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])
अंतराल प्रदर्शित करें
print("IntervalIndex...\n", interval)
विशिष्ट मान समाहित है या नहीं जांचें
print("\nDoes the interval contain a specific value?\n", interval.contains(13))
पूरा उदाहरण
import pandas as pd
# IntervalIndex बनाएं
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])
# अंतराल प्रदर्शित करें
print("IntervalIndex...\n", interval)
# अंतराल लंबाई प्रदर्शित करें
print("\nIntervalIndex length...\n", interval.length)
# अंतराल में विशिष्ट मान समाहित है या नहीं जांचें
print("\nDoes the interval contain a specific value?\n", interval.contains(13))
आउटपुट
IntervalIndex... IntervalIndex([(10, 20], (15, 25]], dtype='interval[int64, right]')
IntervalIndex length... Int64Index([10, 10], dtype='int64')
Does the interval contain a specific value? [ True False]
व्याख्या: मान 13 पहले अंतराल (10, 20] में समाहित है (True) लेकिन दूसरे अंतराल (15, 25] में नहीं (False)।