title: Loop over columns in DF and calculate sum based on condition for every appended column in R or Python
body: <pre><code>A B C
  1 0 0
  0 0 1
  0 1 0
  1 1 1
  </code></pre>
  
  <p>Here I have 4*3 dataframe (columns A,B,C). I`d like to calculate sum in a combination of columns based on a condition that both rows are 1. In other words, in the output I want to have 1*3 dataframe with A 2 B 1 C 1. So, first I look at column A, it has 2 rows with ones, so the sum is 2, then I look at combination of A and B, there is just one row with BOTH 1, so I get 1. Finally, I get combination of A,B,C and it has one row with all ones, so I get 1 as well. Could you pls help with the best way to do it in R or Python.</p>