title: Is there a function in pandas to group data with and without considering a condition at the same time?
body: <p>This is the dataframe:
  <a href="https://i.stack.imgur.com/MkTwG.png" rel="nofollow noreferrer">dataframe</a></p>
  <p>I want to find number of home_matches and number of home_wins for each team in every season.
  So my code is this:</p>
  <pre><code>&gt; home_matches=viewmatches.groupby([&quot;season&quot;,&quot;home_team&quot;])[&quot;home_team&quot;].count().reset_index(name=&quot;home_matches&quot;)
  &gt; home_wins=viewmatches[viewmatches.home_team_goal&gt;viewmatches.away_team_goal].groupby([&quot;season&quot;,&quot;home_team&quot;])[&quot;home_team&quot;].count().reset_index(name=&quot;home_wins&quot;)
  &gt; merged=home_wins.merge(home_matches, on=[&quot;season&quot;,&quot;home_team&quot;]) 
  &gt; merged
  </code></pre>
  <p>and the result is this:
  <a href="https://i.stack.imgur.com/j6RBI.png" rel="nofollow noreferrer">output</a></p>
  <p>But is there another way to get the same result without writing two group by functions and then merging two tables? For example in MySQL for the same result there is an easy query:</p>
  <pre><code>select season, home_team, count(home_team) as home_matches,
  count(if(home_team_goal&gt;away_team_goal,home_team,null)) as home_wins
  from matches_view mv 
  group by season, home_team
  </code></pre>