unitedsaga
unitedsaga

Reputation: 111

Pandas rolling with groupby

I am using a rolling function with win_type as 'gaussian'. However, when i am taking the mean of the data I am receiving a type error. Not sure why this is happening since 'std' is a required input while using 'gaussian' window. Any help is appreciated. Thanks

TypeError: roll_mean() got an unexpected keyword argument 'std'

I have included a sample dataset to recreate this issue

dummy_dta = pd.DataFrame({'id' : ['A', 'A', 'A', 'B', 'B'],
                      'value' : [2,3,4,1,4]})

dummy_dta.groupby('id')['value'].rolling(2, win_type = 'gaussian', min_period = 1).mean(std = 2)    # TypeError
dummy_dta.groupby('id')['value'].rolling(2, win_type = 'gaussian', min_period = 1).mean()    # Runs okay

Upvotes: 1

Views: 218

Answers (1)

Derek O
Derek O

Reputation: 19565

You should update your version of pandas to the latest version 1.1.0, as pointed out the comments.

A good way to figure this out is to check the documentation, which contains a nearly identical example to yours using the .sum() method instead of .mean() but with the same parameters. So if your code breaks and the code in the documentation doesn't, then you probably need to update your version of pandas.

dummy_dta.groupby('id')['value'].rolling(2, win_type = 'gaussian', min_period = 1).mean(std = 2)

Output:

id   
A   0    NaN
    1    2.5
    2    3.5
B   3    NaN
    4    2.5
Name: value, dtype: float64

dummy_dta.groupby('id')['value'].rolling(2, win_type = 'gaussian', min_period = 1).mean() 

Output:

id   
A   0    NaN
    1    2.5
    2    3.5
B   3    NaN
    4    2.5
Name: value, dtype: float64

Upvotes: 1

Related Questions