Created
February 23, 2018 11:42
-
-
Save StevenReitsma/8496a889ddf6b011aa291a5d8b3c5494 to your computer and use it in GitHub Desktop.
Blogpost-Heineken4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SmoothedVarCreator(object): | |
def __init__(self, var, groupby_keys, alpha_list): | |
self.var = var | |
self.groupby_keys = groupby_keys | |
self.alpha_list = alpha_list | |
def transform(self, X): | |
for alpha in self.alpha_list: | |
func = { | |
'%s_sm%s' % (self.var, int(alpha * 10)): lambda df: | |
X.groupby(self.groupby_keys)[self.var].apply(lambda x: x.ewm(alpha=alpha, min_periods=0).mean()) | |
} | |
X = X.assign(**func) | |
return X |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment