pandas.DataFrame.all() Function with example in python

Spread the love

pandas.DataFrame.all(): This function Return whether all elements are True, potentially over an axis.
Syntax: DataFrame.all(axis=0, bool_only=None, skipna=True, level=None, **kwargs)
It Returns True unless there at least one element within a series or along a Dataframe axis that is False or equivalent (e.g. zero or empty).

Parameters:
axis : {0 or ‘index’, 1 or ‘columns’, None}, default 0
Indicate which axis or axes should be reduced.

0 / ‘index’ : reduce the index, return a Series whose index is the original column labels.
1 / ‘columns’ : reduce the columns, return a Series whose index is the original index.
None : reduce all axes, return a scalar.
bool_only : bool, default None
Include only boolean columns. If None, will attempt to use everything, then use only boolean data. Not implemented for Series.

skipna : bool, default True
Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be True, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

level : int or level name, default None
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.

**kwargs : any, default None
Additional keywords have no effect but might be accepted for compatibility with NumPy.

Returns:
Series or DataFrame
If level is specified, then, DataFrame is returned; otherwise, Series is returned.

Example Program:

import pandas as pd import numpy as np df = pd.DataFrame({'x': [1, 2, 2,3,np.nan,0], 'y': [10,20,30,40,50,60]}) print(df.all())

Output:

x    False
y     True
dtype: bool

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *