Skip to content

ENH: access sliced dataframe from rolling.cov #61401

Open
@srkunze

Description

@srkunze

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions