Box Plot of grouped data in Pandas
<p>I am trying to plot a boxplot of a grouped dataset.</p>

<p>Imagine my data set looks like this</p>

<pre><code>Gender | Age
------ | ------
Male   | 20
------ | ------
Female | 40
------ | ------
Female | 45
------ | ------
Unknown| 5
------ | ------
Male   | 80
------ | ------
Female | 30
------ | ------
Unknown| 50
------ | ------
Male   | 12
</code></pre>

<p>Now what I want to do is to plot a box plot which shows the Mean age of all three genders in the same plot figure which looks something like this:</p>

<p><a href="http://i.stack.imgur.com/BR0iK.png" rel="nofollow"><img src="http://i.stack.imgur.com/BR0iK.png" alt="Multi Box plots"></a></p>

<p>Currently what I have done is to group my dataset by Genders.</p>

<pre><code>data = data.groupby("Gender")
data["Age"].plot(kind="box")
</code></pre>

<p>But what this does is produce one box plot like this -</p>

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

<p>How do I unstack them and produce a more meaningful visualization?</p>

<p>I was able to figure it out on my own.</p>

<p>Using the seaborn package, one can simply do this</p>

<pre><code>sns.boxplot(data["Age"], groupby=data["Gender"])
</code></pre>

<p>and it renders a beautiful boxplot grouped</p>

python matplotlib plot