Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display rows where a column is False in pandas

I have a dataframe with one column(dtype=bool) contains True/False values, I want to filter the records if bool column == False

Below script gives error, please help.

if mFile['CCK'].str.contains(['False']):
    print(mFile.loc[mFile['CCK'] == False])

Error in

if mFile['CCK'].str.contains(['False']
like image 715
Learnings Avatar asked Aug 25 '17 11:08

Learnings


1 Answers

You don't need to convert the value to a string (str.contains) because it's already a boolean. In fact, since it's a boolean, if you want to keep only the true values, all you need is:

mFile[mFile["CCK"]]

Assuming mFile is a dataframe and CCK only contains True and False values

Edit: If you want false values use:

mFile[~mFile["CCK"]]
like image 184
con-- Avatar answered Oct 15 '22 19:10

con--