Stack Overflow Asked by learningisfun on December 11, 2020
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]
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)
Answered by ericl16384 on December 11, 2020
Try boolean indexing with all
(for only True values):
df.columns[df.all()]
Output:
Index(['A', 'C', 'E'], dtype='object')
Answered by Quang Hoang on December 11, 2020
8 Asked on January 28, 2021 by gainz
0 Asked on January 27, 2021 by m0bbin
1 Asked on January 27, 2021 by alice-messis
4 Asked on January 27, 2021 by shemtheultimate
2 Asked on January 27, 2021 by kachi-cheong
0 Asked on January 27, 2021 by s-leg3ndz
3 Asked on January 27, 2021
1 Asked on January 27, 2021 by micim987
1 Asked on January 27, 2021 by user13888307
1 Asked on January 27, 2021 by heaven
2 Asked on January 27, 2021 by youtube
1 Asked on January 26, 2021
1 Asked on January 26, 2021 by arbin-bulaybulay
Get help from others!
Recent Answers
© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP