-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: rolling window iterator with on should replace with the window index with the on column #40373
New issue
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
Comments
From the beginning example in the windowing user guide, this is the expected behavior as windowing results are designed to return a result that's the same result as the original DataFrame/Series: https://pandas.pydata.org/docs/user_guide/window.html#windowing-operations As for iterating while specifying |
Sorry I missed that example in the docs. Looking at the example, the first group in |
The first result value is dictated by the |
It says:
So shouldn't |
Correct
|
The above makes sense. What I believe is inconsistent is how it works when used in a for loop:
Outputs:
This is because the first element of the iterator is:
What would make more sense is either for that element to not exist or for the first element to include NaNs so that a Do you agree that |
I believe |
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Prints:
Problem description
With a rolling window all groups should be always the same size (5 in the above example) and so the first 4 groups should be skipped. The first groups are an expanding window which then turn into a rolling window.
Additionally, the API is a bit unexpected when you compare to a
for idx, group in df.groupby('col')
operation. With agroupby
each element also provides the index, whilerolling
it just provides the grouped data and removes the grouping index column (i.e. the columnindex
does not exist ingroup
).Expected Output
Even better it would also include the index so that:
Would work
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : db08276
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-1100-azure
Version : #111~16.04.1-Ubuntu SMP Thu Nov 19 06:49:21 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.4
setuptools : 50.3.1.post20201107
Cython : 0.29.17
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.5
pandas_gbq : None
pyarrow : 3.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.20
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.51.2
The text was updated successfully, but these errors were encountered: