0
user_id     user_verified
1              False
2              False
3              False
4              True
5              False
6              True

How to remove all the 'False'values and keep 'True' values?

2

4 Answers 4

2
df = df[df['user_verified'] == True]

You can check the condition that way. This will keep the row if True in column 2.

You can also drop row based on bolean:

df.drop(df[df['user_verified'] == False].index, inplace=True)

Or even, to keep the True:

df = df[df.user_verified]
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming your data is in a dataframe as specified in a similar format below:

data = pd.DataFrame(zip(range(1,7), [False, False, False, False, True, False, True]), columns=['user_id', 'user_verified'])

You can simply use masking since the user_verified is boolean:

verified = data[data['user_verified']]

Comments

0

There are some ways to do it

df = df[df['user_verified'] == True]

Or you can also use

df = df.loc[df['user_verified'] == True]

Comments

0

Use:

df = df[df['user_verified'] == True] 

or(without creating copy):

df = df.loc[df.user_verified,:]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.