title: Groupby dataframe and count based on column condition
body: <p>I have this kind of Dataframe</p>
  <pre><code>H = Home win
  D = Draw
  A = Away win
  
              Datetime    HomeTeam            AwayTeam            HG  AG  FT
  0   2021-02-17 22:00:00 Colo Colo           U. De Concepcion    1   0   H
  1   2021-02-15 14:30:00 Cobresal            U. Espanola         4   1   H
  2   2021-02-14 22:00:00 Deportes Iquique    S. Wanderers        2   0   H
  3   2021-02-14 22:00:00 La Serena           A. Italiano         0   2   A
  4   2021-02-14 22:00:00 O'Higgins           Colo Colo           1   1   D
  ... ... ... ... ... ... ...
  </code></pre>
  <p>I want to count the previous wins of teams per match in the rows</p>
  <p>Code:</p>
  <pre><code>_hometeam_countH = df.groupby([&quot;HomeTeam&quot;, 'FT' == 'H']).apply(lambda x: x.iloc[1:, :][&quot;FT&quot;].count())
  _hometeam_count = df.groupby(&quot;HomeTeam&quot;).apply(lambda x: x.iloc[1:, :][&quot;FT&quot;].count())
  
  df[&quot;Wins/Match&quot;] = df[&quot;HomeTeam&quot;].apply(lambda x: (_hometeam_countH.loc[x] if x in _hometeam_countH.index else 0) / (_hometeam_count.loc[x] if x in _hometeam_count.index else 0))
  
  </code></pre>
  <p>But got <code>_hometeam_countH = df.groupby([&quot;HomeTeam&quot;, 'FT' == 'H']).apply(lambda x: x.iloc[1:, :][&quot;FT&quot;].count())</code>, <code>KeyError: False</code></p>
  <p>How can I groupby the dataframe by &quot;HomeTeam&quot; and &quot;FT&quot; with a conditions?</p>