How to remove rows from a dataframe if 75 % of its column values is equal to 0
<p>I have a data frame of 44 column and 60,000 rows. I wanted to remove those rows if it has 0 up to 75 % of columns. This 75% :For example in my case out of 44 columns its 33 columns. And so I tried the following function in R
as,</p>

<pre><code>filter &lt;- apply(df, 1,function(x) any(x[1:33]!=0) &amp;&amp; any(x[34:44]!=0) )
df = df[filter,]
</code></pre>

<p>It's perfectly looking for those columns I asked for. But the problem is my data frame has many rows with values like this,for certain rows there is zeros in alternate model ie, one column its numeric value then its zero and so on. This sometimes is more than 33 columns and the above function avoids those rows.</p>

<p>So far I tried in R , any solution which i can try in pandas are also would be also great ..I know when all values are not equal to zero in pandas</p>

<pre><code> df[(df != 0).all(1)]
</code></pre>

<p>Here is how my data frame looks like,</p>

<pre><code>dim(df)
[1] 57905    44
head(df)

     ID Pe_1    Pe_2    Pe_3    Pe_4    Pe_5    Pe_6    Pe_7    Pe_8    Pe_9    Pe_10   Pe_11   Pe_12   Pe_13   Pe_14   Pe_15   Pe_16   Pe_17   Pe_18   Pe_19   Pe_20   Pe_21   Pe_22   Pe_23   Pe_24   Pe_25   Pe_26   Pe_27   Pe_28   Pe_29   Pe_30   Pe_31   Pe_32   Pe_33   Pe_34   Pe_35   Pe_36   Pe_37   Pe_38   Pe_39   Pe_40   Pe_41   Pe_42   Pe_43   Pe_44
ENSG1   0   0   1   0   0   2   2   1   0   0   0   1   0   3   3   0   1   0   2   0   2   3   1   2   0   2   0   0   0   0   0   2   0   0   0   0   2   0   0   2   0   3   1   3
ENSG2   274 293 300 273 229 124 427 291 274 561 128 506 342 540 376 422 411 190 723 224 303 316 766 697 251 167 271 361 325 133 215 274 217 366 227 579 337 254 570 188 143 363 250 359
ENSG3   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG4   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG5   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG6   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG7   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG8   0   1   0   1   1   1   0   2   0   0   0   1   1   1   0   1   0   0   0   0   0   1   1   1   2   1   0   3   0   1   1   2   0   0   0   0   0   0   1   1   0   0   1   1
ENSG9   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG10  3   2   4   6   21  6   6   13  3   1   1   6   10  4   2   0   1   0   0   0   4   2   5   3   25  9   7   10  7   5   3   0   0   5   1   8   4   5   0   4   1   3   2   4
ENSG11  277 43  79  216 1170    174 213 1303    564 14  53  76  170 1016    32  19  69  69  50  21  75  31  560 86  2668    604 513 303 1378    109 219 172 10  1031    276 242 1587    217 76  43  450 81  502 99
</code></pre>

<p>Any suggetsions/help would be great</p>