jeyyu2003
jeyyu2003

Reputation: 57

Pandas checking for False value in Dataframe

I have a csv file that has something like:

col_a, col_b,isactive
a,b,true
c,d,false

I am trying to write all the rows that have true to one file and the ones that are false to one file. I am trying to understand how i can check for the "false" boolean flag in the dataframe.

# this works
df1 = pd.read_csv(all_users)
df_isActive=(df1[df1['isActive']])
df_isActive.to_csv('onlyactive.csv')

# this doesn't work below.
df_isNotActive=(df1[df1['isActive' == 'False']])

I am trying to figure out how to use "Not" inActive in a dataframe.

Thanks,

Upvotes: 0

Views: 565

Answers (3)

wwnde
wwnde

Reputation: 26676

Can also try

m=df.isactive==False
df[m]

enter image description here

Upvotes: 1

BENY
BENY

Reputation: 323226

A quick way

df_isNotActive=df1.drop(df_isActive.index)

Upvotes: 2

Anshul
Anshul

Reputation: 1413

Try this:

df_isNotActive = (df1[~df1['isActive']])

Upvotes: 2

Related Questions