title: Python: Add a column to a crosstab based on value and condition
body: <p>I have a Pandas crosstab created from NumPy arrays of zeros and ones. After creating crosstab by:<code>ct = pd.crosstab(index=np.array(labels), columns=np.array(cols)</code> I have a crosstab that looks like:</p>
  
  <pre><code>col_0     0     1 
  row_0
  ---------------------
  0        618    53   
  1        53     79
  </code></pre>
  
  <p>I wanted to add a column in here for error percentages on false positives and false negatives. I added a new column to the crosstab using <code>ct[2] = ct.apply(lambda row: row[0] + row[1], axis = 1)</code> which added a column of sum of the first two columns. I would like to add a fourth column that would calculate ct[0][0] divided by the sum for the first row, and ct[1][1] divided by the sum for the second row, and add that column to ct[3]. I tried:</p>
  
  <pre><code>for i,y in ct.iterrows():
     ct[3] = ct.apply(lambda y: y[i]/y[2] , axis = 1)
  </code></pre>
  
  <p>but since it executes twice, it will overwrite the column with the 2nd result. I tried using <code>ct[3][i]</code> to no avail. Using <code>lambda y: y[1] if y==0 else y[0]</code> doesn't work. What is the method for adding a new column to the dataframe / crosstab, with a condition-based calculation on existing values?</p>