जांचने के लिए कि पैंडास इंडेक्स में केवल बूलियन हैं या नहीं, पैंडास में index.is_boolean() मेथड का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें:
import pandas as pd
पैंडास इंडेक्स बनाएं:
index = pd.Index([True, True, False, False, True, True, True])
पैंडास इंडेक्स प्रदर्शित करें:
print("Pandas Index...\n",index)
जांचें कि इंडेक्स वैल्यूज में केवल बूलियन हैं या नहीं:
print("\nIndex values only consists of booleans?\n",index.is_boolean())
उदाहरण
निम्न कोड है:
import pandas as pd
# पैंडास इंडेक्स बनाना
index = pd.Index([True, True, False, False, True, True, True])
# पैंडास इंडेक्स प्रदर्शित करना
print("Pandas Index...\n",index)
# इंडेक्स में एलिमेंट्स की संख्या लौटाएं
print("\nNumber of elements in the index...\n",index.size)
# डेटा का dtype लौटाएं
print("\nThe dtype object...\n",index.dtype)
# जांचें कि इंडेक्स वैल्यूज में केवल बूलियन हैं या नहीं
print("\nIndex values only consists of booleans?\n",index.is_boolean())
आउटपुट
यह निम्न आउटपुट देगा:
Pandas Index... Index([True, True, False, False, True, True, True], dtype='object') Number of elements in the index... 7 The dtype object... object Index values only consists of booleans? True