我有一个DataFrame
与datetime
索引和价格列。我想要ohlc数据。 (开放,高,低,关闭)熊猫:获取每一行的欧元数据
我想在给定频率在每行重新采样此数据帧。
frame.resample('60S', how = 'ohlc')
有效,但现在数据帧的索引间隔60秒。我想在前面60年代的每行中重新抽样。 (如果索引相隔5秒,则为12)。这样我可以为原始数据帧中的每一行提供ohlc值。
我不认为我想要做的事可能与df.resample
但可能与.agg
或.map
?
我该如何获得的每个行的ohlc数据?
n = 10000
prices = np.linspace(100.0, 103.0, n) + np.random.normal(0.0, 0.3, n)
f = pd.DataFrame({'price': prices}, index = pd.date_range(end = datetime.utcnow(), freq = '5S', periods = n))
ohlcized = f.resample('60S', how = 'ohlc') # resampling doesnt work (834 != 10000)
len(ohlcized) # 834
len(f) # 10000
if len(ohlcized) == len(f):
print "question answered"
能否请您提供一些样本数据? – Alexander
完成。如果你需要我澄清更多,我可以。问题是重采样会删除行。我希望保留所有的数据,并在过去的60S数据的每一行预先形成'ohlc'操作。 –