I'm new to python and I have found tons of my questions have already been answered. In 7 years of coding various languages, I've never actually posted a question on here before, so I'm really stumped this time.
I'm using python 3.6
I have a pandas dataframe with a column that is just Boolean values. I have some code that I only want to execute if all of the rows in this column are True.
Elsewhere in my code I have used:
if True not in df.column:
to identify if not even a single row in df is True. This works fine.
But for some reason the converse does not work:
if False not in df.column:
to identify if all rows in df are True.
Even this returns False:
import pandas as pd
S = pd.Series([True, True, True])
print(False not in S)
But I have found that adding .values to the series works both ways:
import pandas as pd
S = pd.Series([True, True, True])
print(False not in S.values)
The other alternative I can think of is to loop through the column and use the OR operator to compare each row with a variable initialized as True. Then if the variable makes it all the way to the end as True, all must be true.
SO my question is: why does this return False?
import pandas as pd
S = pd.Series([True, True, True])
print(False not in S)