

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Check if the Pandas Index only consists of booleans
<p>To check if the Pandas Index only consists of booleans, use the <strong>index.is_boolean()</strong> method in Pandas. At first, import the required libraries -</p><pre class="just-code notranslate language-python3" data-lang="python3">import pandas as pd</pre><p>Creating Pandas index</p><pre class="just-code notranslate language-python3" data-lang="python3">index = pd.Index([True, True, False, False, True, True, True]) </pre><p>Display the Pandas index −</p><pre class="just-code notranslate language-python3" data-lang="python3">print("Pandas Index... ",index)</pre><p>Check whether index values have only booleans −</p><pre class="just-code notranslate language-python3python" data-lang="python3">print(" Index values only consists of booleans? ",index.is_boolean()) </pre><h2>Example</h2><p>Following is the code −</p><pre class="demo-code notranslate language-python3" data-lang="python3">import pandas as pd # Creating Pandas index index = pd.Index([True, True, False, False, True, True, True]) # Display the Pandas index print("Pandas Index... ",index) # Return the number of elements in the Index print(" Number of elements in the index... ",index.size) # Return the dtype of the data print(" The dtype object... ",index.dtype) # check whether index values has only booleans print(" Index values only consists of booleans? ",index.is_boolean())</pre><h2>Output</h2><p>This will produce the following output −</p><pre class="result notranslate">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</pre>
- Related Questions & Answers
- Python - Check if the Pandas Index only consists of integers
- Python - Check if the Pandas Index only consists of numeric data
- Python Pandas - Check if the index has NaNs
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python - Check if the Pandas Index is of the object dtype
- Python Pandas - Check if the index has unique values
- Python Pandas - Check if the index has duplicate values
- Python - Check if the Pandas Index holds categorical data
- Python - Check if the Pandas Index is a floating type
- Python Pandas - Check if the index is empty with 0 elements
- Python Pandas - Return if the index is monotonic increasing (only equal or increasing) values
- Python Pandas - Return if the index is monotonic decreasing (only equal or decreasing) values
- Python - Check if the Pandas Index with some NaNs is a floating type
- Python Pandas - Return the Transpose of the index
- Python Pandas - Set the name of the index
Advertisements