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?

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58

4 Answers4

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]
Synthase
  • 5,849
  • 2
  • 12
  • 34
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']]
mustious
  • 51
  • 4
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]
0

Use:

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

or(without creating copy):

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