Skip to content
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

rolling method: use time window and win_type #26980

Open
phineas-pta opened this issue Jun 21, 2019 · 2 comments
Open

rolling method: use time window and win_type #26980

phineas-pta opened this issue Jun 21, 2019 · 2 comments
Labels
Enhancement Window rolling, ewma, expanding

Comments

@phineas-pta
Copy link

I have the same problem with this StackOverflow post, I reproduce it here. The goal is to calculate weighted time-based moving average over an irregular time series

Code Sample

import pandas as pd
from pandas.tseries.frequencies import to_offset

dft = pd.DataFrame(
    {'B': [0, 1, 2, 3, 4]},
    index = pd.Index(
        [
            pd.Timestamp('20130101 09:00:00'),
            pd.Timestamp('20130101 09:00:02'),
            pd.Timestamp('20130101 09:00:03'),
            pd.Timestamp('20130101 09:00:05'),
            pd.Timestamp('20130101 09:00:06')
        ],
        name = 'foo'
    )
)
dft.rolling('2s').sum() # worked
dft.rolling('2s', win_types='triang').sum() # error: Invalid window
dft.rolling(to_offset('2s'), win_types='triang').sum() # error: Invalid window
dft.rolling(pd.Timedelta('2s'), win_types='triang').sum() # error: Invalid window

Problem description

the .rolling method doesn't accept a time window and not-default window type

I look at the documentation and try with offset window but still have the same problem

If it's not possible to use time window, could you please update the documentation

Output of pd.show_versions()

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: None.None

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.5.0
sphinx: 2.1.0
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.1.0
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.3.4
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
@WillAyd
Copy link
Member

WillAyd commented Jun 21, 2019

I think this could work but would need to be implemented. Any interest in contributing?

@WillAyd WillAyd added the Window rolling, ewma, expanding label Jun 21, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Jun 21, 2019
@ihsansecer
Copy link
Contributor

This will require calculating window weights multiple times since window sizes are variable. I am not sure how to approach this. Does calculating (and storing) all weights beforehand same as fixed window implementation is fine?

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

4 participants