pyspark.pandas.DataFrame.any

DataFrame.any(axis: Union[int, str] = 0, bool_only: Optional[bool] = None) → Series

Return whether any element is True.

Returns False unless there is at least one element within a series that is True or equivalent (e.g. non-zero or non-empty).

Parameters
axis{0 or ‘index’}, 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.

bool_onlybool, default None

Include only boolean columns. If None, will attempt to use everything, then use only boolean data.

Returns
Series

Examples

Create a dataframe from a dictionary.

>>> df = ps.DataFrame({
...    'col1': [False, False, False],
...    'col2': [True, False, False],
...    'col3': [0, 0, 1],
...    'col4': [0, 1, 2],
...    'col5': [False, False, None],
...    'col6': [True, False, None]},
...    columns=['col1', 'col2', 'col3', 'col4', 'col5', 'col6'])

Default behaviour checks if column-wise values all return True.

>>> df.any()
col1    False
col2     True
col3     True
col4     True
col5    False
col6     True
dtype: bool

Include only boolean columns when set bool_only=True.

>>> df.any(bool_only=True)
col1    False
col2     True
dtype: bool

Returns empty Series when the DataFrame is empty. >>> df[[]].any() Series([], dtype: bool)