Loop over multiple columns in dataframe
<p>I have a dataframe from a CSV file that has 61 columns and 1mil rows. 25 of those columns <code>(Flag_1, Flag_2, ..., Flag_25)</code> have <code>True/False</code> as values for each row of the dataframe.</p>

<p>What I'm trying to do is loop through each column to determine if there is a True for that entire row within those columns, I just need a minimum of one true. If there is a True then a new column, <code>Flag_All</code> will have a True value for that row, if not, then False.</p>

<p>I can use the for loop for a single column like so,</p>

<pre><code>for index, x in data2['FLAG_1'].iteritems() :
    data2['FLAG_ALL'] =  data2['FLAG_1'] == True
</code></pre>

<p>but can't figure out for multiple columns.  </p>

<p>Please try:</p>

<pre><code>data2['FLAG_ALL'] = data2.any(axis=1,bool_only=True).values 
</code></pre>

<p>More info on <strong>any()</strong> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.any.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.any.html</a></p>

python pandas for-loop dataframe