Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({'cat':list('aabbc'),
'v':range(5)}, dtype=object)
df.groupby('cat').boxplot(subplots=False, column='v')
results in the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/src/pandas/pandas/plotting/_core.py", line 604, in boxplot_frame_groupby
return plot_backend.boxplot_frame_groupby(
File "/src/pandas/pandas/plotting/_matplotlib/boxplot.py", line 485, in boxplot_frame_groupby
ret = df.boxplot(
File "/src/pandas/pandas/plotting/_core.py", line 511, in boxplot_frame
return plot_backend.boxplot_frame(
File "/Users/ian/src/pandas/pandas/plotting/_matplotlib/boxplot.py", line 414, in boxplot_frame
ax = boxplot(
File "/src/pandas/pandas/plotting/_matplotlib/boxplot.py", line 391, in boxplot
data = data[columns]
File "/src/pandas/pandas/core/frame.py", line 3504, in __getitem__
indexer = self.columns._get_indexer_strict(key, "columns")[1]
File "/src/pandas/pandas/core/indexes/multi.py", line 2559, in _get_indexer_strict
return super()._get_indexer_strict(key, axis_name)
File "/src/pandas/pandas/core/indexes/base.py", line 5510, in _get_indexer_strict
self._raise_if_missing(keyarr, indexer, axis_name)
File "/src/pandas/pandas/core/indexes/multi.py", line 2579, in _raise_if_missing
return super()._raise_if_missing(key, indexer, axis_name)
File "/src/pandas/pandas/core/indexes/base.py", line 5570, in _raise_if_missing
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [MultiIndex([('a', 'v'),\n ('b', 'v'),\n ('c', 'v')],\n )] are in the [columns]"
Issue Description
This might be related to #16748
Expected Behavior
The same as:
import pandas as pd
df = pd.DataFrame({'cat':list('aabbc'),
'v':range(5)})
df.groupby('cat').boxplot(subplots=False, column='v')
Installed Versions
pandas : 1.4.0.dev0+634.ga951998314
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 52.0.0.post20210125
Cython : 0.29.24
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None