If you want to check whether the entire dataframe contains only True
boolean values then all you need is
df.eq(True).all()
and the output will be a Series
that indicates whether each column has True
values. For instance,
>>> import pandas as pd
>>> df = pd.DataFrame({'col1': [True, True], 'col2': [True, False], 'col3': [True, None]})
>>> df.eq(True).all()
col1 True
col2 False
col3 False
dtype: bool
Now if you want the output to be a single boolean value then you can apply all()
on the above:
>>> df.eq(True).all().all()
False
- eq() can be used to perform element-wise comparisons
- all() is used to check whether all elements are
True
, potentially over an axis.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…