groupby boxplot doesn't work if multiple by's are used · Issue #14701 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

data = pd.DataFrame({'A': [1, 1, 2, 2], 'B': ['a', 'b', 'a', 'b'], 'value': [1, 2, 3, 4]}) data.groupby(['A', 'B']).boxplot()

Problem description

This code fails with an obscure error message from the internals:

KeyError                                  Traceback (most recent call last)
<ipython-input-118-d3ffaf6e9196> in <module>()
----> 1 data.groupby(['A', 'B']).boxplot()

/home/languitar/miniconda2/envs/monitoring/lib/python2.7/site-packages/pandas/tools/plotting.pyc in boxplot_frame_groupby(grouped, subplots, column, fontsize, rot, grid, ax, figsize, layout, **kwds)
   3109                               rot=rot, grid=grid, **kwds)
   3110             ax.set_title(pprint_thing(key))
-> 3111             ret.loc[key] = d
   3112         fig.subplots_adjust(bottom=0.15, top=0.9, left=0.1,
   3113                             right=0.9, wspace=0.2)

/home/languitar/miniconda2/envs/monitoring/lib/python2.7/site-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
    137         else:
    138             key = com._apply_if_callable(key, self.obj)
--> 139         indexer = self._get_setitem_indexer(key)
    140         self._setitem_with_indexer(indexer, value)
    141

/home/languitar/miniconda2/envs/monitoring/lib/python2.7/site-packages/pandas/core/indexing.pyc in _get_setitem_indexer(self, key)
    124
    125         try:
--> 126             return self._convert_to_indexer(key, is_setter=True)
    127         except TypeError as e:
    128

/home/languitar/miniconda2/envs/monitoring/lib/python2.7/site-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
   1227                 mask = check == -1
   1228                 if mask.any():
-> 1229                     raise KeyError('%s not in index' % objarr[mask])
   1230
   1231                 return _values_from_object(indexer)

There is no hint in the documentation that this could be an illegal operation.

Expected Output

It should just print a boxplot for all groups, or if this really doesn't work, give a real hint why.

Output of pd.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 4.8.8-1-ARCH machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.19.0
nose: None
pip: 8.1.2
setuptools: 27.2.0
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None