How can I implement something similar to `value_counts()` in a groupby?
<p>Suppose I had the following data</p>

<pre><code>Orchard    Tree
1           Apple
2           Peach
1           Peach
3           Apple
</code></pre>

<p>How could I group by <code>orchard</code> and show how many times each tree occurs in the orchard?  The result would look like</p>

<pre><code>Tree     Apple  Peach
Orchard
1          1     1
2          0     1
3          1     0
</code></pre>

<p>Let's not forget good ol' <code>value_counts</code><br>
Just have to make sure to reduce to <code>Tree</code> after the <code>groupby</code></p>

<pre><code>df.groupby('Orchard').Tree.value_counts().unstack(fill_value=0)
</code></pre>

<p><a href="https://i.stack.imgur.com/Gl9ZY.png" rel="nofollow"><img src="https://i.stack.imgur.com/Gl9ZY.png" alt="enter image description here"></a></p>

python pandas dataframe