Question

In: Computer Science

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

How can I reduce data set by deleting any rows that have all FALSE bool 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. True and False in the table are dtype 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

Solutions

Expert Solution

Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.


Below is the output of the program:
Contents of del.csv:

Console output:

Below is the code to copy:
#CODE STARTS HERE----------------
import pandas as pd
#reading sample csv from a file
df = pd.read_csv("del.csv", delimiter="\t")
print("ORIGINAL DATAFRAME:")
print(df) #prints original dataframe
print("\nMODIFIED DATAFRAME:")
#df.iloc[:,2:] => selects all rows with columns from 2 to end. This removes 'test1' and 'id'
#.any(axis=1) => returns true if there is atleast 1 'True' in the column
#df[~df.iloc[:,2:].any(axis=1)] => prints rows where all values are 'False'
print(df[~df.iloc[:,2:].any(axis=1)]) #Prints modified df
#CODE ENDS HERE-----------------

Related Solutions

OK I have two data sets with 30 million rows each each data set is five...
OK I have two data sets with 30 million rows each each data set is five columns with four attributes and an amount. I want to confirm that the two data sets are exactly the same no two rows of data in the 30 million rolls are duplicates For my proof I will confirm each data set has the same number of rows. And I will also do the following: I will create four smaller data sets from each of...
I need a copy of organized data in a spreadsheet with rows and columns labeled, can...
I need a copy of organized data in a spreadsheet with rows and columns labeled, can anyone help me with this please? I am doing a made up experiment where I see if eating vegetarian diets makes someone healthier. I am ‘supposed’ to find a group of people at school willing to participate and change their diet, pull their names from a jar, and randomly assign who will try the vegetarian diet and who’s diet will remain the same that...
Suppose that a block can contain at most four data values and that all data values...
Suppose that a block can contain at most four data values and that all data values are integers. Using only B+ trees of degree 2, give examples of each of the following : a. A B+ tree whose height changes from 2 to 3 when the value 42 is inserted. Show your structure before and after the insertion. b. A B+ tree in which the deletion of the value 42 leads to a redistribution. Show your structure before and after...
You and I could have different intrinsic values. True or False?
You and I could have different intrinsic values. True or False?
How can you have a basis through the spanning set theorem? I thought the spanning set...
How can you have a basis through the spanning set theorem? I thought the spanning set has to be linear independent? Doesn't the spanning set theorem say that the vectors in the set are linear dependent as you can them as a linear combination of each other? Am I overthinking this or am I getting this wrong? **UPDATED I think I have the answer to my question, we use the theorem to basically turn the set into a linearly independent...
I have the appropriate data set. This is the question: How much variance in maximum wind...
I have the appropriate data set. This is the question: How much variance in maximum wind speed is explained by atmospheric pressure? With a one-unit change in atmospheric pressure, what is the corresponding change in maximum wind speed?   Can you tell me the procedure to use in SPSS in order to answer these questions?
True or False) The following code will output "I was true". bool isGreater(string s1, string s2)...
True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; }
Hello, i Have an OPAMP of 66dB ,how using negative feedback we can reduce the closed...
Hello, i Have an OPAMP of 66dB ,how using negative feedback we can reduce the closed loop gain to 16dB Thanks
How can I create a normal distribution in excel when the only data I have is...
How can I create a normal distribution in excel when the only data I have is mean and standard deviation?
You can use any language. You have to provide all the data, output and input. You...
You can use any language. You have to provide all the data, output and input. You are to use Linked Lists to do this Program. The XYZ Widget store receives shipments of widgets at various costs. The store’s policy is to charge a 30% markup, and to sell widgets which were received earlier before widgets which were received later. This is called a FIFO policy. Write a program using linked lists that reads in three types of input data and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT