Remove several rows with zero values in a dataframe using python
<p>HI everybody i need some help with python. </p>

<p>I'm working with an excel with several rows, some of this rows has zero value in all the columns, so i need to delete that rows. </p>

<pre><code>In 
 id a b c d 
 a  0 1 5 0 
 b  0 0 0 0
 c  0 0 0 0
 d  0 0 0 1 
 e  1 0 0 1

Out 
id a b c d 
a  0 1 5 0
d  0 0 0 1 
e  1 0 0 1
</code></pre>

<p>I think in something like show the rows that do not contain zeros, but do not work because is deleting all the rows with zero and without zero </p>

<pre><code>path = '/Users/arronteb/Desktop/excel/ejemplo1.xlsx'
xlsx = pd.ExcelFile(path)
df = pd.read_excel(xlsx,'Sheet1')
df_zero = df[(df.OTC != 0) &amp; (df.TM != 0) &amp; (df.Lease != 0) &amp; (df.Maint != 0) &amp; (df.Support != 0) &amp; (df.Other  != 0)]
</code></pre>

<p>Then i think like just show the columns with zero </p>

<pre><code>In 
id a b c d 
a  0 1 5 0 
b  0 0 0 0
c  0 0 0 0
d  0 0 0 1 
e  1 0 0 1


Out 
id a b c d 
b  0 0 0 0
c  0 0 0 0   
</code></pre>

<p>So i make a little change and i have something like this </p>

<pre><code>path = '/Users/arronteb/Desktop/excel/ejemplo1.xlsx'
xlsx = pd.ExcelFile(path)
df = pd.read_excel(xlsx,'Sheet1')
df_zero = df[(df.OTC == 0) &amp; (df.TM == 0) &amp; (df.Lease == 0) &amp; (df.Maint == 0) &amp; (df.Support == 0) &amp; (df.Other  == 0)]
</code></pre>

<p>In this way I just get the column with zeros. I need a way to remove this 2 rows from the original input, and receive the output without that rows. Thanks, and sorry for the bad English, I'm working on that too</p>

<p>For this dataframe:</p>

<pre><code>df
Out: 
  id  a  b  c  d  e
0  a  2  0  2  0  1
1  b  1  0  1  1  1
2  c  1  0  0  0  1
3  d  2  0  2  0  2
4  e  0  0  0  0  2
5  f  0  0  0  0  0
6  g  0  2  1  0  2
7  h  0  0  0  0  0
8  i  1  2  2  0  2
9  j  2  2  1  2  1
</code></pre>

<p>Temporarily set the index:</p>

<pre><code>df = df.set_index('id')
</code></pre>

<p>Drop rows containing all zeros and reset the index:</p>

<pre><code>df = df[~(df==0).all(axis=1)].reset_index()

df
Out: 
  id  a  b  c  d  e
0  a  2  0  2  0  1
1  b  1  0  1  1  1
2  c  1  0  0  0  1
3  d  2  0  2  0  2
4  e  0  0  0  0  2
5  g  0  2  1  0  2
6  i  1  2  2  0  2
7  j  2  2  1  2  1
</code></pre>

python excel dataframe