There is a DataFrame df:
a b
1 True
2 True
3 False
How do you make a subset of column a where column b is True?
output:
a
1
2
Use loc with boolean indexing and instead mask use column b:
...if need Series add a:
s = df.loc[df.b, 'a']
print (s)
0 1
1 2
Name: a, dtype: int64
...if need DataFrame (one column) add a in list:
df1 = df.loc[df.b, ['a']]
print (df1)
a
0 1
1 2
And for all columns need boolean indexing only:
df1 = df[df.b]
print (df1)
a b
0 1 True
1 2 True
Also is possible use query:
print (df.query('b')['a'])
0 1
1 2
Name: a, dtype: int64
print (df.query('b')[['a']])
a
0 1
1 2
print (df.query('b'))
a b
0 1 True
1 2 True
df[df.b].... seriously you could've googled this