Skip to content

ENH: built-in shift function that shifts each row by a different period, given by a Series. #41385

@glorencini

Description

@glorencini

Is your feature request related to a problem?

No

Describe the solution you'd like

I would like a built-in shift function that shifts each row by a different period, given by a Series.

API breaking implications

It would improve the shift possibilities.

Describe alternatives you've considered

Using shift with apply and lambda.

Additional context

[add any other context, code examples, or references to existing implementations about the feature request here]

def shift_df_by_series(self, df=pd.DataFrame, s=pd.Series) -> pd.DataFrame:
    return df.apply(lambda shifted_df: shifted_df.shift(periods=s[shifted_df.name], fill_value=0), axis='columns')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closing CandidateMay be closeable, needs more eyeballsEnhancementNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions