In pandas dataframe, generate third column data based on results in two other columns
<p>I'm a newbie to dataframes.  I have columns <code>A</code>, <code>B</code> and <code>C</code> and want to use the data in A and B to create a value in C.  For example, if <code>A = 1</code> and/or <code>B = 1</code>, then I want to place a <code>1</code> in column <code>C</code> and do this logic for all rows in the dataframe.</p>

<p>e.g. starting array:</p>

<pre><code>         A  B  C
0        1  0  
1        0  1  
2        1  1  
3        0  0  
</code></pre>

<p>etc  </p>

<p>resulting array:</p>

<pre><code>         A  B  C
0        1  0  1
1        0  1  1
2        1  1  1
3        0  0  0
</code></pre>

<p>etc</p>

<p>Given a starting DF of:</p>

<pre><code>df = pd.DataFrame({'A': [1, 0, 1, 0], 'B': [0, 1, 1, 0]})
</code></pre>

<p>Then you can create column <code>C</code> as such:</p>

<pre><code>df['C'] = (df == 1).any(axis=1).astype(int)
</code></pre>

<p>Then leaves <code>df</code> as:</p>

<pre><code>   A  B  C
0  1  0  1
1  0  1  1
2  1  1  1
3  0  0  0
</code></pre>

python pandas dataframe boolean condition