Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.any#

DataFrame.any(*,axis=0,bool_only=False,skipna=True,**kwargs)[source]#

Return whether any element is True, potentially over an axis.

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

Parameters:
axis{0 or ‘index’, 1 or ‘columns’, None}, default 0

Indicate which axis or axes should be reduced. ForSeries this parameteris unused and defaults to 0.

  • 0 / ‘index’ : reduce the index, return a Series whose index is theoriginal column labels.

  • 1 / ‘columns’ : reduce the columns, return a Series whose index is theoriginal index.

  • None : reduce all axes, return a scalar.

bool_onlybool, default False

Include only boolean columns. Not implemented for Series.

skipnabool, default True

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

**kwargsany, default None

Additional keywords have no effect but might be accepted forcompatibility with NumPy.

Returns:
Series or DataFrame

If level is specified, then, DataFrame is returned; otherwise, Seriesis returned.

See also

numpy.any

Numpy version of this method.

Series.any

Return whether any element is True.

Series.all

Return whether all elements are True.

DataFrame.any

Return whether any element is True over requested axis.

DataFrame.all

Return whether all elements are True over requested axis.

Examples

Series

For Series input, the output is a scalar indicating whether any elementis True.

>>>pd.Series([False,False]).any()False>>>pd.Series([True,False]).any()True>>>pd.Series([],dtype="float64").any()False>>>pd.Series([np.nan]).any()False>>>pd.Series([np.nan]).any(skipna=False)True

DataFrame

Whether each column contains at least one True element (the default).

>>>df=pd.DataFrame({"A":[1,2],"B":[0,2],"C":[0,0]})>>>df   A  B  C0  1  0  01  2  2  0
>>>df.any()A     TrueB     TrueC    Falsedtype: bool

Aggregating over the columns.

>>>df=pd.DataFrame({"A":[True,False],"B":[1,2]})>>>df       A  B0   True  11  False  2
>>>df.any(axis='columns')0    True1    Truedtype: bool
>>>df=pd.DataFrame({"A":[True,False],"B":[1,0]})>>>df       A  B0   True  11  False  0
>>>df.any(axis='columns')0    True1    Falsedtype: bool

Aggregating over the entire DataFrame withaxis=None.

>>>df.any(axis=None)True

any for an empty DataFrame is an empty Series.

>>>pd.DataFrame([]).any()Series([], dtype: bool)

[8]ページ先頭

©2009-2025 Movatter.jp