Skip to content

ENH: access sliced dataframe from rolling.cov #61401

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
2 of 3 tasks
srkunze opened this issue May 6, 2025 · 0 comments
Open
2 of 3 tasks

ENH: access sliced dataframe from rolling.cov #61401

srkunze opened this issue May 6, 2025 · 0 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@srkunze
Copy link

srkunze commented May 6, 2025

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

In a current project, I iterate over df.rolling(window).cov(pairwise=True). Currently, I back-calculate from the index value of the cov() and the window offset what I suspect to be the start of the window. Then I slice the original df again into the window.

It would be great to iterate efficiently over the original df simultaneously with the cov values (and possibly with all the other window functions).

Feature Description

An idea off the top off my head:

for window, cov in df.rolling(window).roll("window", "cov_pairwise"):
    ...
    # window equals df.loc[start:end]
    # cov equals df.loc[start:end].cov()
    # start equals window.index[0]
    # end equals window.index[-1]
    ...

Alternative Solutions

I don't know any. Maybe there is already a way to do this.

Additionally, roll could allow efficient slicing to avoid useless calculations

for window, cov in df.rolling(window).roll("window", "cov_pairwise")[-1000:]:
    ...

Additional Context

No response

@srkunze srkunze added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels May 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant