I have a dataframe
[1] df
ProductIds A B C D
11210000018 0 0 0 0
11210000155 1 0 0 0
11210006508 0 0 0 0
11210007253 0 0 0 0
11210009431 0 0 0 0
11210135871 1 0 0 0
I want to filter the frame by adding each row and if sum is greater than zero then filter that row. For the given condition the result would be like
ProductIds A B C D
11210000155 1 0 0 0
11210135871 1 0 0 0
One way of doing that is to add another column with sum and then filter like the following:
df['Sum'] = df.sum(axis = 1)
df = df[df.Sum > 0]
df.drop(['Sum']
But is there any one liner builtin method to do this ? I cannot add the columns manually because there are thousands of columns. Thanks.
df = df[df.sum(axis=1) > 0]