Skip to content

DataFrameGroupBy.idxmin() returns DataFrame, documentation says Series #15275

Closed
@pganssle

Description

@pganssle

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame([[0, 0],
                  [3, 0],
                  [1, 1]], index=list('ABC'), columns=list('ab'))

gby = df.groupby(by='b')

print(type(gby))            # <class 'pandas.core.groupby.DataFrameGroupBy'>
print(type(gby.idxmin()))   # <class 'pandas.core.frame.DataFrame'>

Problem description

According to the documentation, this is supposed to output a pandas.core.Series. To me, that seems to be what makes sense, but I'm not sure how or why this ended up returning a DataFrame. Is this just an issue with the documentation, or is it an issue with the code?

Edit: Ah, I understand why this returns a DataFrame now - if you have multiple columns the idxmin() might be different for each column. Seems that the documentation needs to be updated. I can make a PR if that's appropriate.

Output of pd.show_versions()

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

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 34.0.3
Cython: 0.25.2
numpy: 1.12.0
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
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: None
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions