Reputation: 181
Given a dataframe df, I need to select the columns that have only True values
df =
A B C D E
True False True False True
Output should be
output = [A, C, E]
Upvotes: 2
Views: 1757
Reputation: 364
Try iterating through it and putting the keys in a list (you can easily modify this to result in a dict, though).
result = []
for i in df.keys():
if df[i].all():
result.append(i)
Upvotes: 1
Reputation: 150765
Try boolean indexing with all
(for only True values):
df.columns[df.all()]
Output:
Index(['A', 'C', 'E'], dtype='object')
Upvotes: 4