Python | Pandas Index.all()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Index.all()
function checks if all the elements in the index are true or not. It returns one single boolean value if axis is not specified. It returns true if each individual value in the index are true. It returns false if any of the values in the index is not true.
Note : It treats 0 as false value.
Syntax: Index.all(*args, **kwargs)
Parameters :
*args : These parameters will be passed to numpy.all
**kwargs : These parameters will be passed to numpy.allReturns : all : bool or array_like (if axis is specified)
A single element array_like may be converted to bool.
Example #1: Use Index.all()
function to check if all values are true in the index.
# importing pandas as pd import pandas as pd # Creating the Index df = pd.Index([ 10 , 44 , 5 , 25 , 74 ]) # Print the Index df |
Output :
Let’s check if all the values in the index are true or not.
# to check if index values are true or not df. all () |
Output :
As we can see in the output, the function has returned true indicating all the values in the index are true.
Example #2: Use Index.all()
function to check if all the values are true in the index. In the index we are having some 0 values.
# importing pandas as pd import pandas as pd # Creating the Index df = pd.Index([ 17 , 69 , 33 , 5 , 0 , 74 , 0 ]) # Print the dataframe df |
Output :
Let’s check if all the values in the index are true or it is having any false values as well.
# to check if there is any false # value present in the index df. all () |
Output :
Recommended Posts:
- Python | pandas.map()
- Python | Pandas Index.contains()
- Python | Pandas Series.str.contains()
- Python | Pandas dataframe.sem()
- Python | Pandas dataframe.add()
- Python | Pandas DataFrame.loc[]
- Python | Pandas Index.where
- Python | Pandas Series.str.pad()
- Python | Pandas Period.day
- Python | Pandas Timestamp.tz
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas Dataframe.at[ ]
- Python | Pandas Period.second
- Python | Pandas Series.std()
- Python | Pandas Series.take()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.