When a DataFrame ("Given_DF") has a Boolean variable (such as B below),how can one subset the DataFrame to keep only rows of Variable B with True value?.
Given_DF
ID A B
0 123 True
1 456 False
2 789 False
3 132 True
4 465 False
The 'Desired' subset is the DataFrame with only two rows (with ID 0 and 3).
Tried subsetting B as a column,
Desired = Given_DF["B"].isin(True)Tried indexing the variable B and using loc to subset to "True" incidences B.
prep.sort_index(level=["B"]) Desired = prep.loc["True"]
Neither attempts worked. Help would be appreciated.
The same way you subset with any other type. Put an expression that matches your condition inside the subscript of the df.
or more simply
.isin()is used when you have a collection of values you want to match, butTrueis not a collection. You'd have to write.isin([True])for this to work.