Boxplot with pandas groupby multiindex, for specified sublevels from multiindex
This should work in version 0.16:
data['2013-08-17'].boxplot(by='SPECIES')
this code:
data['2013-08-17'].boxplot(by='SPECIES')
Will not work, as boxplot is a function for a DataFrame and not a Series.
While in Pandas > 0.18.1 the boxplot function has the argument columns
which defines from what column the data is taken from.
So
data.boxplot(column='2013-08-17',by='SPECIES')
should return the desired result.
An example with the Iris dataset:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('https://raw.githubusercontent.com/pandas-dev/pandas/master/pandas/tests/io/data/csv/iris.csv')
fig, ax = plt.subplots(figsize=(10,8))
plt.suptitle('')
data.boxplot(column=['SepalLength'], by='Name', ax=ax)
creates:
plt.suptitle('')
turns off the annoying automatic subtitle. And of course the column arguments accepts lists of columns... so
data.boxplot(column=['SepalLength', 'SepalWidth'], by='Name', ax=ax)
also works.
I think I figured it out, maybe this will be helpful to someone:
grouped = data['2013-08-17'].groupby(axis=1, level='SPECIES').T
grouped.boxplot()
Basically groupby output needed to be transposed so that the boxplot showed the right grouping: