Find rows with non zero values in a subset of columns in pandas dataframe
<p>I have a datframe with 4 columns of strings and others as integers. Now I need to find out those rows of data where at least one of the column is a non-zero value (or > 0).</p>

<pre><code>manwra,sahAyaH,T7,0,0,0,0,T
manwra, akriti,T5,0,0,1,0,K 
awma, prabrtih,B6, 0,1,1,0,S
</code></pre>

<p>My output should be</p>

<pre><code>manwra, akriti,T5,0,0,1,0,K 
awma, prabrtih,B6, 0,1,1,0,S
</code></pre>

<p>I have tried the following to obtain the answer. The string values are in colums 0,1,2 and -1 (last column).</p>

<pre><code>KT[KT.ix[:,3:-2] != 0]
</code></pre>

<p>What I am receiving as output is </p>

<pre><code>NaN,NaNNaN,NaN,NaN,NaN,NaN,NaN
NaN,NaN,NaN,NaN,NaN,1,NaN,NaN
NaN,NaN,NaN,NaN,1,1,NaN,NaN
</code></pre>

<p>How to obtain the desired output</p>

<p>Here is an alternative solution which uses <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.select_dtypes.html" rel="nofollow">select_dtypes()</a> method:</p>

<pre><code>In [41]: df[(df.select_dtypes(include=['number']) != 0).any(1)]
Out[41]:
        0          1   2  3  4  5  6  7
1  manwra     akriti  T5  0  0  1  0  K
2    awma   prabrtih  B6  0  1  1  0  S
</code></pre>

<p>Explanation:</p>

<pre><code>In [42]: df.select_dtypes(include=['number']) != 0
Out[42]:
       3      4      5      6
0  False  False  False  False
1  False  False   True  False
2  False   True   True  False

In [43]: (df.select_dtypes(include=['number']) != 0).any(1)
Out[43]:
0    False
1     True
2     True
dtype: bool
</code></pre>

python pandas dataframe