I have a pandas series of mostly zeroes with some ones, I'd like to "create tails" or "smoothen" the ones, but I'm missing the required statistics background to express what I want to google it.
Expressed as code, I have source
and want to make it into target
source = pd.Series([0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0])
target = pd.Series([0.0, 1.0, 0.7, 0.4, 0.1, 0.0, 0.0, 1.0, 0.7, 0.4, 0.1, 1.0, 0.7, 0.4])
source.plot(drawstyle="steps-pre")
target.plot(drawstyle="steps-pre")
Blue line is source and orange is target
How is this operation called? Bonus points for how to do it in pandas/numpy/scipy
CodePudding user response:
It's a convolution: Two functions are involved. One is your original data, the other is called the "kernel" or "filter." In your case the kernel is [1.0, 0.7, 0.4, 0.1]. The result is obtained by multiplying the two together while offsetting the kernel step by step. There are algorithms that can be more efficient than brute force, found under the general topic of "digital filtering."