Apply function on cumulative values of pandas series

user1507844

Is there an equivalent of rolling_apply in pandas that applies function to the cumulative values of a series rather than the rolling values? I realize cumsum, cumprod, cummax, and cummin exist, but I'd like to apply a custom function.

Ffisegydd

You can use pd.expanding_apply. Below is a simple example which only really does a cumulative sum, but you could write whatever function you wanted for it.

import pandas as pd

df = pd.DataFrame({'data':[10*i for i in range(0,10)]})

def sum_(x):
    return sum(x)


df['example'] = pd.expanding_apply(df['data'], sum_)

print(df)

#   data  example
#0     0        0
#1    10       10
#2    20       30
#3    30       60
#4    40      100
#5    50      150
#6    60      210
#7    70      280
#8    80      360
#9    90      450

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python pandas: apply a function with arguments to a series. Update

From Dev

Getting previous row values from within pandas apply() function

From Dev

Pandas Groupby apply function to count values greater than zero

From Dev

pandas apply function that returns multiple values to rows in pandas dataframe

From Dev

Cleaner pandas apply with function that cannot use pandas.Series and non-unique index

From Dev

Pandas cumulative function of series with dates and NaT

From Dev

Apply function row wise on pandas data frame on columns with numerical values

From Dev

Pandas function that iterates over values in a series with case statements

From Dev

How to apply a function on a Series

From Dev

how do I apply normalize function to pandas string series?

From Dev

Cumulative Sum Function on Pandas Data Frame

From Dev

Apply function with args in pandas

From Dev

Pandas Apply lambda function null values

From Dev

Apply function to pandas dataframe row using values in other rows

From Dev

Apply custom cumulative function to pandas dataframe

From Dev

Dealing with None values when using Pandas Groupby and Apply with a Function

From Dev

Cumulative Ranking of Values in Pandas with Ties

From Dev

How to apply a function on a series of columns, based on the values in a corresponding series of columns?

From Dev

Pandas apply function to multindexed columns that takes columns (Series) as arguments

From Dev

Pandas cumulative sum if between certain times/values

From Dev

Apply Customize Cumulative Function to Pandas

From Dev

Using pandas groupby and apply for cumulative integration

From Dev

python pandas: apply a function with arguments to a series. Update

From Dev

Pandas: merging Series values

From Dev

Getting previous row values from within pandas apply() function

From Dev

Pandas: Timing difference between Function and Apply to Series

From Dev

how do I apply normalize function to pandas string series?

From Dev

Pandas Apply lambda function null values

From Dev

Using purrr to apply cumulative function

Related Related

  1. 1

    python pandas: apply a function with arguments to a series. Update

  2. 2

    Getting previous row values from within pandas apply() function

  3. 3

    Pandas Groupby apply function to count values greater than zero

  4. 4

    pandas apply function that returns multiple values to rows in pandas dataframe

  5. 5

    Cleaner pandas apply with function that cannot use pandas.Series and non-unique index

  6. 6

    Pandas cumulative function of series with dates and NaT

  7. 7

    Apply function row wise on pandas data frame on columns with numerical values

  8. 8

    Pandas function that iterates over values in a series with case statements

  9. 9

    How to apply a function on a Series

  10. 10

    how do I apply normalize function to pandas string series?

  11. 11

    Cumulative Sum Function on Pandas Data Frame

  12. 12

    Apply function with args in pandas

  13. 13

    Pandas Apply lambda function null values

  14. 14

    Apply function to pandas dataframe row using values in other rows

  15. 15

    Apply custom cumulative function to pandas dataframe

  16. 16

    Dealing with None values when using Pandas Groupby and Apply with a Function

  17. 17

    Cumulative Ranking of Values in Pandas with Ties

  18. 18

    How to apply a function on a series of columns, based on the values in a corresponding series of columns?

  19. 19

    Pandas apply function to multindexed columns that takes columns (Series) as arguments

  20. 20

    Pandas cumulative sum if between certain times/values

  21. 21

    Apply Customize Cumulative Function to Pandas

  22. 22

    Using pandas groupby and apply for cumulative integration

  23. 23

    python pandas: apply a function with arguments to a series. Update

  24. 24

    Pandas: merging Series values

  25. 25

    Getting previous row values from within pandas apply() function

  26. 26

    Pandas: Timing difference between Function and Apply to Series

  27. 27

    how do I apply normalize function to pandas string series?

  28. 28

    Pandas Apply lambda function null values

  29. 29

    Using purrr to apply cumulative function

HotTag

Archive