title: How to compare two dataframes in pandas?
body: <p>I have a dataframe like this:</p>
  <pre><code>df = pd.DataFrame([[1,'aaa',50],[0,'aaa',1000],[0,'aba',30],[1,'aaa',50],[1,'aba',10]], 
  columns=['A','B','C'])
  df
  
  
  
      A   B   C
  0   1   aaa 50
  1   0   aaa 1000
  2   0   aba 30
  3   1   aaa 50
  4   1   aba 10
  </code></pre>
  <p>I want for each item in 'B'(which also there are repeated items), check its value in 'A'. If it's 1, it should calculate the sum of values in 'C' for that item. If it's 0, it should count the number of items which their 'A' value is zero. Then the final result would be: sum/count.</p>
  <p>In the end, I want to show the result like this:</p>
  <pre><code>    ID  Value
  0   aaa 100
  1   aba 10
  </code></pre>
  <p>For example, 'aaa' has two 1 which their sum is 50 + 50 = 100, and one 0 which its count is 1. So the result is 100 / 1 = 100.</p>
  <p>How can I do something like that in an efficient way? I tried to use groupby() and have the sum and count in different dataframes, but I don't know how to compare them and get this result.</p>