I have the following Pandas DataFrame in Python:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.array([[1, 2, 3, 4, 5, 6], [11, 22, 33, 44, 55, 66],
[111, 222, 0, 0, 0, 0], [1111, 0, 0, 0, 0, 0]]),
columns=['a', 'b', 'c', 'd', 'e', 'f'])
DataFrame looks as the following in a table:
a b c d e f
0 1 2 3 4 5 6
1 11 22 33 44 55 66
2 111 222 0 0 0 0
3 1111 2222 0 0 0 0
The original DataFrame is much bigger than this. As seen, some rows have zero values in some columns (c, d, e, f).
I need to remove these columns from the DataFrame so that my new DataFrame will look as the following (after removing rows where given columns are zeros only):
a b c d e f
0 1 2 3 4 5 6
1 11 22 33 44 55 66
And I only need to remove the rows where all these column (c, d, e, and f) are zeros. If, for example, 2 of them are 0, then I will not remove such rows.
Is there a good way of doing this operation without looping through the DataFrame?