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
the group_keys argument is only to impact .groupby(...).apply and not other methods. Closing for now - if you think I've missed something, comment here and we can reopen.
Indeed, you are right, the docs specifically mention the group_keys for the apply method.
To give some context to my inquiry, when calling say shift(1) on the groupby there is no repetition of the index and you get a result with the same index as the original data.
df.price.groupby("ticker").shift(1)
However when calling rolling(2).mean() there is repetition of the index. How do we know which method duplicates the index and which does not? And how do we fix the duplicate index ?
So here, I was hoping that group_keys=False would do the trick.
As a side note, I noticed that using as_index=False at the dataframe level fixes the issue.
I still think the result in my example is wrong, even if the problem is not with the group_keys flag. So if you don't mind, I will create a different issue with a rephrased explanation.
Thank you
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 groupby followed by a rolling calculation ignores group_keys=False.
In the example below the column ticker appears twice in the result even though we have
group_keys=False
Expected Behavior
The groupby column 'ticker' should not repeat since we have group_keys=False.
Installed Versions
INSTALLED VERSIONS
commit : bdc79c1
python : 3.9.18.final.0
python-bits : 64
OS : Darwin
OS-release : 23.3.0
Version : Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.1
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 24.0
Cython : None
pytest : 8.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.18.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.3
numba : 0.59.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: