我有开放范围/第一个小时(美国东部标准时间上午 9:30-10:30)的基于分钟的 OHLCV 数据。我希望重新采样这些数据,以便获得一个 60 分钟的值,然后计算范围。
当我对数据调用 dataframe.resample() 函数时,我得到两行,第一行从上午 9:00 开始。我希望只有一排从上午 9:30 开始。
注意:初始数据从 9:30 开始。
编辑:添加代码:
# Extract data for regular trading hours (rth) from the 24 hour data set
rth = data.between_time(start_time = '09:30:00', end_time = '16:15:00', include_end = False)
# Extract data for extended trading hours (eth) from the 24 hour data set
eth = data.between_time(start_time = '16:30:00', end_time = '09:30:00', include_end = False)
# Extract data for initial balance (rth) from the 24 hour data set
initial_balance = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False)
卡住试图按个别日期分隔开盘范围并获取初始余额
conversion = {'Open' : 'first', 'High' : 'max', 'Low' : 'min', 'Close' : 'last', 'Volume' : 'sum'}
sample = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False)
sample = sample.ix['2007-05-07']
sample.tail()
sample.resample('60Min', how = conversion)
默认情况下,重新采样从整点开始。我希望它从数据开始的地方开始。
最佳答案
您可以使用 resample
的 base
参数:
sample.resample('60Min', how=conversion, base=30)
来自 the above docs-link :
base
:int
, default 0
For frequencies that evenly subdivide 1 day, the “origin” of the aggregated intervals.
For example, for ‘5min’ frequency, base could range from 0 through 4. Defaults to 0
关于python - 重新采样分钟数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14861023/