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. Assuming there are 20+ columns/rows to loop through. 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 Bool.

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

Code:

import pandas as pd
df = pd.read_csv('test.csv')
a = []
for i, row in df.iterrows():
if(int(row['value1'])==0 and int(row['value2'])==0 and int(row['value3'])==0 and int(row['value4'])==0):
a.append(i)
df = df.drop(a)

Dataframe Before deleting:

Dataframe after deleting:

Hope this helps.

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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT