title: Pandas groupby and count numbers of item by conditions
body: <p>I have a dataframe like this:</p>
  <pre><code>df_test = pd.DataFrame({'ID1':['A','A','A','A','A','A','B','B','B','B'],
                         'ID2':['a','a','a','aa','aaa','aaa','b','b','bb','bb'],
                         'ID3':['c1','c2','c3','c4','c5','c6','c7','c8','c9','c10'],
                         'condition':['','!','','!','','','!','','','!']})
  </code></pre>
  <p><a href="https://i.stack.imgur.com/xSdj9.png" rel="nofollow noreferrer">df_test</a></p>
  <p>I want group by them by ID1. the result dataframe need to like this (the count_condition means the number of '!')for each ID2 group:</p>
  <pre><code>df_test_result = pd.DataFrame({'ID1':['A','A','A','B','B'],
                         'ID2':['a','aa','aaa','b','bb'],
                          'Count_ID2':[3,1,2,2,2],
                          'Count_ID3':[3,1,2,2,2],
                          'Count_condition': [1,1,0,1,1]})
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Flav7.png" rel="nofollow noreferrer">df_test_result</a></p>
  <p>I have tried to use groupby and agg to obtain this result, but I can not get the number of '!' for each group. here's my command</p>
  <pre><code>df_test_result = df_test.groupby(['ID1','ID2']).agg({'ID2':'count','ID3':'nunique','condition':'count'})
  </code></pre>
  <p>if there's a kind of command like this wrong one:</p>
  <pre><code>df_test = df_test.groupby(['ID1','ID2']).agg({'ID2':'count','ID3':'nunique','condition' == '!':'count'})
  </code></pre>