-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
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
import io
import pandas as pd
DATA = """
ticker,date,price,volume
AAA,2021-01-01,10.0,1000
AAA,2021-01-02,11.0,1000
AAA,2021-01-03,12.0,1000
AAA,2021-01-04,11.0,1000
BBB,2021-01-01,20.0,1000
BBB,2021-01-02,21.0,1000
BBB,2021-01-03,22.0,1000
BBB,2021-01-04,21.0,1000
"""
f = io.StringIO(DATA)
df = pd.read_csv(f, parse_dates=['date'], index_col=[0, 1])
df.price.groupby("ticker", group_keys=False).rolling(2).mean()
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
df.price.groupby("ticker", group_keys=False).rolling(2).mean()
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