Skip to content

Add an apply_rolling_window helper to pd_utils. #18

@bmmalone

Description

@bmmalone

The idea is that this function applies a function to overlapping rows in a data frame (that is, a "rolling window"). A basic implementation is as follows:

def apply_rolling_window(df, func, window_size, progress_bar=False):
    
    it = range(len(df))
    
    if progress_bar:
        it = tqdm.trange(len(df))
        
    ret = [
        func(df.iloc[i: i+window_size])
            for i in it
    ]

    return ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions