【发布时间】:2019-01-30 17:35:32
【问题描述】:
我有一个 pandas 数据框,其中有日期时间(不在索引中,并且更喜欢这种方式)。 我想将其上采样(重新采样)到指定的时间尺度,例如“10S”。并将字符串数据(即 Acitivty/Action/EPIC 等列)也保留在 dataFrame 中。
Ind TIME_STAMP Activity Action Quantity EPIC Price Sub-activity Venue Position
0 2018-08-22 08:01:36 Allocation SELL 100.0 BB. 1.142200 CPTY 300AD -427.0
1 2018-08-22 08:02:17 Allocation BUY 15.0 BB. 1.152300 CPTY ZDDD02 -388.0
2 2018-08-22 08:24:51 Allocation SELL 60.0 BB. 1.165900 CPTY 666 -515.0
3 2018-08-22 09:07:59 NaN NaN NaN NaN 1.167921 NaN -515.0
4 2018-08-22 09:11:00 NaN NaN NaN NaN 1.174500 NaN
我尝试了几种不同的方法,即 dataFrame.asfreq(freq = '10S');和 dataFrame.resample('10S', on ='TIME_STAMP')
我真正想做的是 1) 将数据上采样到 10 秒的块中,保留原始数据,2) 使用“TIME_STAMP”列。 3) 之后,可以使用 .fillna(method ='pad') 等填充方法来填充数值数据
【问题讨论】:
标签: python-3.x pandas time-series resampling