I want to implement exponential filter.
- column "value" is unfiltered value
- column "alfa" is current weight of the filter
- column "value_filtered" is output, i.e. filtered value.
I need to use it in combination with pandas groupby. pseudo code:
- value_filtered[0] = value[0];
- for i>0: value_filtered[i] = (1-alfa[i])* value_filtered[i-1] + alfa[i] *value[i]
Example is below:
data_out = [['group1', 0, 1,1],['group1', 0.5, 2, 1.5],['group1', 0.6, 3, 2.4], ['group2', 0, 10, 10],['group2', 0.5, 20, 15],['group2', 0.6, 30, 24], ]
df_out = pd.DataFrame(data_out, columns=['group', 'alfa', 'value', 'value_filtered'])
df_out
I looked to the post below, but there the filter weight is static, while in my case it is defined in column "alfa" and does not work with groupby. apply a recursive function to a pandas dataframe column