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>

<pre><code>def f(x):

    if (x.B==1) and (x.A !=1): #Or whatever logic you like
        return 1
    else: 
        return 0

df['C'] = df.apply(lambda x: f(x), axis = 1)
</code></pre>

python pandas dataframe boolean condition