+3 votes
in Programming Languages by (60.0k points)
A DataFrame contains only boolean values: True/False. How can I check whether all values in the dataframe are True?

1 Answer

+1 vote
by (353k points)
selected by
Best answer

The all() function of Pandas DataFrame can be used to check whether all elements along a given axis are True. However, if you provide argument axis=None, it will check all elements in the DataFrame.

Here is an example:

>>> import pandas as pd
>>> df1 = pd.DataFrame({'A':[True, True, True],'B':[True,True,True]})
>>> df1.all(axis=None)
>>> df2 = pd.DataFrame({'A':[True, True, True],'B':[False,True,True]})
>>> df2.all(axis=None)