You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If [] is added, the Series is returned; if [[]] is added, the DataFrame is returned. It is not necessary to include the group key("group" or "date") in the []/[[]].
For multi-groups, pd.Grouper() can be used. It is working the same way.
However, groupby().resample() works a little differently. It cannot return the DataFrame without passing key columns of resample().
df_re.groupby("group").resample("10D", on="date").mean()
df_re.groupby("group").resample("10D", on="date")["val"].mean() # -> Seriesdf_re.groupby("group").resample("10D", on="date")[["val"]].mean()
# -> KeyError: 'The grouper name date is not found'
I think this behavior is unnatural. (Even if this is not a bug, this error message is difficult to understand.)
Expected Behavior
df_re.groupby("group").resample("10D", on="date")[["val"]].mean() should return a DataFrame which is equal to df_re.groupby("group").resample("10D", on="date")[["val", "date"]].mean() and df_re.groupby("group").resample("10D", on="date")["val"].mean().to_frame()
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Japanese_Japan.932
Thanks @wany-oh for the report and detailed investigation.
I think this behavior is unnatural. (Even if this is not a bug, this error message is difficult to understand.)
I agree. The only difference between df_re.groupby("group").resample("10D", on="date")[["val"]].mean() and df_re.groupby("group").resample("10D", on="date")["val"].mean() should be the return type, DataFrame vs Series to be consistent with groupby, resample and indexing in general.
Pandas version checks
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 main branch of pandas.
Reproducible Example
Issue Description
I have a DataFrame.
The following is simple
groupby()
andresample()
case.If
[]
is added, the Series is returned; if[[]]
is added, the DataFrame is returned. It is not necessary to include the group key("group"
or"date"
) in the[]
/[[]]
.For multi-groups,
pd.Grouper()
can be used. It is working the same way.However,
groupby().resample()
works a little differently. It cannot return the DataFrame without passing key columns ofresample()
.I think this behavior is unnatural. (Even if this is not a bug, this error message is difficult to understand.)
Expected Behavior
df_re.groupby("group").resample("10D", on="date")[["val"]].mean()
should return a DataFrame which is equal todf_re.groupby("group").resample("10D", on="date")[["val", "date"]].mean()
anddf_re.groupby("group").resample("10D", on="date")["val"].mean().to_frame()
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Japanese_Japan.932
pandas : 1.4.2
numpy : 1.21.6
pytz : 2022.1
dateutil : 2.8.2
pip : 22.1.2
setuptools : 62.3.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : 2022.5.0
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.2
numba : 0.55.1
numexpr : 2.8.0
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: