1 回答
TA贡献1817条经验 获得超14个赞
一个想法是首先过滤重复的索引值以进行重新采样,就像您的解决方案一样,然后过滤重复到added系列,按楼层更改索引并通过排序添加到原始索引值:
print (orders)
cum
timestamp
2020-03-01 01:11:42.520 -674.0
2020-03-01 02:00:48.778 -700.0
2020-03-01 02:00:58.850 -702.0
2020-03-01 11:45:23.741 -1249.0
2020-03-02 01:56:51.021 -1229.0
2020-03-02 01:56:51.021 -917.0
2020-03-02 01:56:51.021 -837.0
2020-03-02 01:56:54.021 -67.0
mask = orders.index.duplicated()
cum = (orders.loc[~mask, 'cum']
.resample('1S')
.bfill()
.ffill()
)
added = orders.loc[mask, 'cum']
added.index = added.index.floor('S')
cum = added.append(cum).sort_index()
print (cum.tail(10))
timestamp
2020-03-02 01:56:47 -1229.0
2020-03-02 01:56:48 -1229.0
2020-03-02 01:56:49 -1229.0
2020-03-02 01:56:50 -1229.0
2020-03-02 01:56:51 -1229.0
2020-03-02 01:56:51 -917.0
2020-03-02 01:56:51 -837.0
2020-03-02 01:56:52 -67.0
2020-03-02 01:56:53 -67.0
2020-03-02 01:56:54 -67.0
Name: cum, dtype: float64
添加回答
举报