+3 votes
in Programming Languages by (56.8k 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 (349k 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)
True
>>> df2 = pd.DataFrame({'A':[True, True, True],'B':[False,True,True]})
>>> df2.all(axis=None)
False
>>>


...