Pandas Resample With Overlap
I would like to resample my time indexed DataFrame with some overlapping. For example: >>> df data date 2018-03-09 12:00:00 1
Solution 1:
Assuming your data are regularly spaced you can concat
the shifted Series and then take a sum.
N = 10 # Every 10 seconds from first row
ov = 2 # 2s overlap on either sidepd.concat([df.shift(i).iloc[::N] for i in range(-ov, N+ov)], axis=1).sum(1)
date2018-03-09 12:00:00 3.02018-03-09 12:00:10 15.02018-03-09 12:00:20 28.02018-03-09 12:00:30 34.0dtype:float64
For multiple columns, turn this into a groupby
along the columns axis:
df['data2'] = df['data']+1 # Another column
(pd.concat([df.shift(i).iloc[::N] for i in range(-ov, N+ov)], axis=1)
.groupby(level=0, axis=1).sum())
data data2
date
2018-03-09 12:00:00 3.0 6.0
2018-03-09 12:00:10 15.0 28.0
2018-03-09 12:00:20 28.0 42.0
2018-03-09 12:00:30 34.0 46.0
Post a Comment for "Pandas Resample With Overlap"