यह जाँचने के लिए कि पंडों के सूचकांक में अंतराल वस्तुएँ हैं या नहीं, index.is_interval() का उपयोग करें पंडों में विधि।
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import pandas as pd
इंटरवल ऑब्जेक्ट बनाएं -
interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50)
अंतराल प्रदर्शित करें -
print("Interval1...\n",interval1)
print("Interval2...\n",interval2) इंटरवल ऑब्जेक्ट1 और 2 के साथ पांडा इंडेक्स बनाना -
index = pd.Index([interval1,interval2])
जाँचें कि क्या अनुक्रमणिका मानों में केवल अंतराल वस्तुएँ हैं -
print("\nDoes Index consists of Interval objects?\n", index.is_interval()) उदाहरण
निम्नलिखित कोड है -
import pandas as pd
# create Interval objects
interval1 = pd.Interval(10, 30)
interval2 = pd.Interval(30, 50)
# display the intervals
print("Interval1...\n",interval1)
print("Interval2...\n",interval2)
# Creating Pandas index with Interval object1 and 2
index = pd.Index([interval1,interval2])
# Display the Pandas index
print("\nPandas Index...\n",index)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# check whether index values has only ints
print("\nDoes Index consists of Interval objects?\n", index.is_interval()) आउटपुट
यह निम्नलिखित आउटपुट देगा -
Interval1... (10, 30] Interval2... (30, 50] Pandas Index... IntervalIndex([(10, 30], (30, 50]], dtype='interval[int64, right]') The dtype object... interval[int64, right] Does Index consists of Interval objects? True