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

1 Answer

0 votes
by (48.9k points)

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)