Pandas DataFrame | all method
Start your free 7-days trial now!
Pandas DataFrame.all(~)
method checks each row or column, and returns True
for that row/column if all its values evaluate to True
.
Parameters
1. axis
link | int
or string
| optional
Whether to check each row, column or the entire DataFrame:
Axis | Description |
---|---|
| Checks each column. |
| Checks each row. |
| Returns |
By default, axis=0
.
2. bool_only
| None
or boolean
| optional
Whether or not to only consider rows or columns that just have boolean entries in them. By default, bool_only=None
.
3. skipna
| boolean
| optional
If
True
, thenNaN
s are ignored. If all values in the row/column areNaN
, then the method returns aTrue
.If
False
, thenNaN
s are treated asTrue
.
By default, skipna=True
.
4. level
| int
or string
| optional
The level to target. This is only relevant if the source DataFrame is a multi-index. By default, level=None
.
Return value
If axis=None
, then a single boolean is returned. Otherwise, a DataFrame of booleans is returned.
Examples
Consider the following DataFrame:
df
A B0 3 True1 0 1
Checking each column
For each column, to check whether or not all its values evaluate to True
:
df.all() # axis=0
A FalseB Truedtype: bool
Here, note the following:
we get
False
for columnA
because the value0
is internally equivalent toFalse
.similarly,
True
is returned for columnB
because the value1
represents aTrue
boolean.
Checking each row
For each row, to check whether or not all its values evaluate to True
:
df.all(axis=1)
0 True1 Falsedtype: bool
Checking entire DataFrame
To check whether or not all the values in the DataFrame evaluates to True
:
df.all(axis=None)
False