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 pandas as pd
df = pd.DataFrame(
{"foo": list(range(0, 5)), "bar": list(range(1, 6)), "baz": list(range(2, 7))},
)
print(df.rolling(window=3, on='foo').max())
# bar baz
#0 NaN NaN
#1 NaN NaN
#2 3.0 4.0
#3 4.0 5.0
#4 5.0 6.0
df2 = pd.DataFrame(
{"foo": list(range(0, 5)), "bar": list(range(1, 6)), "baz": list(range(2, 7))},
index=['1', '2', '3', '4', '5'],
)
print(df2.rolling(window=3, on='foo').max())
# foo bar baz
#1 0 NaN NaN
#2 1 NaN NaN
#3 2 3.0 4.0
#4 3 4.0 5.0
#5 4 5.0 6.0
Issue Description
According to the document,
For a DataFrame, a column label or Index level on which
to calculate the rolling window, rather than the DataFrame's index.
Provided integer column is ignored and excluded from result since
an integer index is not used to calculate the rolling window.
The column 'foo' should be exclude from the final results. But with a string index, it still shows up in the result.
Expected Behavior
The column 'foo' should be exclude from the final results.
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.9.16.final.0
python-bits : 64
OS : Darwin
OS-release : 21.4.0
Version : Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.5.3
numpy : 1.23.5
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.6.3
pip : 23.0.1
Cython : 0.29.33
pytest : 7.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.11.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None