python - pandas rolling_apply cumprod -


i trying rolling cumulative product series in pandas. in input series is,

   s 0  1 1  2 2  3 3  4 4  5 5  6 

i resulting series gives me cumulative product of previous 'n' values. if 'n' 3, get,

   s 0  n/a 1  n/a 2  6 3  24 4  60 5  120 

the code have come uses rolling_apply , lambda function , produces typeerror

import pandas pnd df = pnd.dataframe() df['s'] = [1,2,3,4] print (df) print (pnd.rolling_apply(df.s,2,lambda x : x.cumprod()))  typeerror: length-1 arrays can converted python scalars 

does know how this?

thanks user2357112. code came works...

import pandas pnd df = pnd.dataframe() df['s'] = [1,2,3,4, 5, 6] print (df) print (pnd.rolling_apply(df.s,3,lambda x : x.prod())) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -