तत्ववार जाँच करने के लिए कि क्या IntervalIndex में अंतराल में मान है, IntervalIndex का उपयोग करें। शामिल हैं () पंडों में विधि।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
इंटरवलइंडेक्स बनाएं -
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
# Create IntervalIndex
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])
# Display the interval
print("IntervalIndex...\n",interval)
# Display the interval length
print("\nIntervalIndex length...\n",interval.length)
# Check if the interval contains a specific value
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]