We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
RollingGroupby.agg
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
import pandas as pd X = pd.DataFrame({"group": [1, 2, 2, 3, 3, 3], "other": [1, 1, 1, 1, 1, 1]}) X.groupby(["group"])[["group"]].rolling(2, min_periods=1).agg("count")
A DataFrame with no columns is returned.
Empty DataFrame Columns: [] Index: [(1, 0), (2, 1), (2, 2), (3, 3), (3, 4), (3, 5)]
As an FYI, X.groupby(["group"])["group"].rolling(2, min_periods=1).agg("count") seems fine
X.groupby(["group"])["group"].rolling(2, min_periods=1).agg("count")
group 1 0 1.0 2 1 1.0 2 2.0 3 3 1.0 4 2.0 5 2.0 Name: group, dtype: float64
as does X.groupby(["group"])[["other"]].rolling(2, min_periods=1).agg("count")
other group 1 0 1.0 2 1 1.0 2 2.0 3 3 1.0 4 2.0 5 2.0
as does X.groupby(["group"])["other"].rolling(2, min_periods=1).agg("count")
group 1 0 1.0 2 1 1.0 2 2.0 3 3 1.0 4 2.0 5 2.0 Name: other, dtype: float64
Also, the problem does not seem to persist if we don't perform a non collapsing aggregation:
X.groupby(["group"])[["group"]].agg("count")
group group 1 1 2 2 3 3
but does if we perform expanding aggregation:
X.groupby(["group"])[["group"]].expanding(min_periods=1).agg("count")
It would output the same as when one does
X.groupby(["group"])[["other"]].rolling(2, min_periods=1).agg("count")
but with "group" as the column name.
"group"
INSTALLED VERSIONS ------------------ commit : a671b5a8bf5dd13fb19f0e88edc679bc9e15c673 python : 3.10.11.final.0 python-bits : 64 OS : Darwin OS-release : 22.4.0 Version : Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 machine : arm64 processor : arm byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.1.4 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 65.5.0 pip : 23.0.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.19.0 pandas_datareader : None bs4 : None bottleneck : None dataframe-api-compat: None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.4 qtpy : None pyqt5 : None
The text was updated successfully, but these errors were encountered:
Thanks for the report, related to #40341 (comment) (cc @mroeschke, @jbrockmendel).
The rest of groupby will keep the grouping column if you select it, e.g.
df[["a", "b"]].groupby("a")[["a", "b"]].sum()
will sum both a and b in the result. I think we should agree with that here.
a
b
Sorry, something went wrong.
RollingGroupby
No branches or pull requests
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
A DataFrame with no columns is returned.
As an FYI,
X.groupby(["group"])["group"].rolling(2, min_periods=1).agg("count")
seems fineas does
X.groupby(["group"])[["other"]].rolling(2, min_periods=1).agg("count")
as does
X.groupby(["group"])["other"].rolling(2, min_periods=1).agg("count")
Also, the problem does not seem to persist if we don't perform a non collapsing aggregation:
X.groupby(["group"])[["group"]].agg("count")
but does if we perform expanding aggregation:
X.groupby(["group"])[["group"]].expanding(min_periods=1).agg("count")
Expected Behavior
It would output the same as when one does
but with
"group"
as the column name.Installed Versions
The text was updated successfully, but these errors were encountered: