Question

How can I reduce data set by deleting any rows that have all FALSE values for...

How can I reduce data set by deleting any rows that have all FALSE values for every column in
that row using pandas. Example: The table data below the pandas code should drop/reduce the data to remove the second & fifth row. Treat The Dtype for the True and False values as object.

id Test1 value1 value2 value3 value4
0.1 1 False False False False
0.2 2 False True True False
0.3 3 True False False False
0.4 4 False False False False

Homework Answers

Answer #1

Assuming the name of the pandas Dataframe is df we first get all the indexes of the rows for which every column has value False.After this we simply delete the required indexes using inplace = True so that it gets permanently deleted from the dataset not just the dataframe.

​
# Get indexes where value1,value2,value3,value4 column has False value

indexNames = df[ (df['value1'] == 'False') & (df['value2'] == 'False') & (df['value3'] == 'False') & (df['value4'] == 'False') ].index

df.drop(indexNames , inplace=True)

​
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions