Pandas DataFrame all() 方法
定义和用法
all()
方法为每一列返回一个值,如果该列中的所有值均为 True,则返回 True,否则返回 False。
通过指定列轴 (axis='columns'
),如果该轴中的所有值均为 True,则 all()
方法将返回 True。
实例
检查每行(索引)中的所有值是否均为 True:
import pandas as pd data = [[True, False, True], [True, True, True]] df = pd.DataFrame(data) print(df.all())
语法
dataframe.all(axis, bool_only, skipna, level, kwargs)
参数
axis
, bool_only
, skipna
, level
参数是关键字参数。
参数 | 值 | 描述 |
---|---|---|
axis |
|
可选。要检查的轴。 默认为 0。 |
bool_only |
|
可选。指定是否仅检查布尔列。 默认为 None。 |
skip_na |
|
可选。如果结果不应跳过 NULL 值,请设置为 False。 默认为 True。 |
level |
|
可选。指定要沿其计数的层级(在分层多级索引中)。 默认为 None。 |
kwargs | 可选。关键字参数。这些参数没有影响,但可以被 NumPy 函数接受 |
返回值
由 True 和 False 值组成的 Series。
如果指定了 level 参数,则此方法将返回 DataFrame 对象。
此函数不会对原始的 DataFrame 对象进行修改。