Time Series Normalization By Event
Suppose I've a python dict as follows, for each product, key is timestamp and value is price of product at that timestamp. data_dict = { 'product_1' : {1: 415, 2: 550, 3: 0, 4: 5
Solution 1:
You may use .apply
method, but that tends to be in-efficient if you have many columns;
So starting with this frame:
>>>df
product_1 product_2 product_3 product_4
1 415 400 500 0
2 550 300 400 200
3 0 300 0 200
4 550 0 500 300
5 600 300 500 300
you define a synchronizing function as in:
>>>defsync(ts):... vals = ts.values... n, k = len(vals), np.where(vals == 0)[0][0]...return Series(vals, np.arange(-k, n - k))
and apply it column-wise:
>>> df.apply(sync).T
-3-2-101234
product_1 NaN4155500550600NaNNaN
product_2 4003003000300NaNNaNNaN
product_3 NaN5004000500500NaNNaN
product_4 NaNNaNNaN0200200300300
.T
at the end for transpose.
Post a Comment for "Time Series Normalization By Event"