【发布时间】:2018-07-29 18:34:30
【问题描述】:
我花了几个小时想出最有效的方法来构建流动的刻度数据并将其附加到 shared memory numpy 数组,然后及时获得 pandas DataFrame。 p>
#source tick data comes in as dict
tick_data = {"bid": float(1.2), "ask": float(1.3), "time": datetime.datetime.now()}
#construct np array
dtype_conf = [('bid', '<f4'), ('ask', '<f4'), ('time', 'datetime64[us]')]
new_tick = np.array([(11.11, 22.22, now)], dtype=dtype_conf)
#append / vstack / .. it to existing shared numpy array
shared_np_array = np.vstack((shared_np_array, new_tick))
#fast construction of pd.DataFrame if needed
pd.DataFrame(shared_np_array.reshape((1,-1))[0])
问题:
1) 构建我的数组并(更快地)向其中添加新的刻度数据的正确方法是什么?
2) 为完整数组创建 pd.DataFrame 或为列创建 pd.Series 最有效的方法是什么?
3) 有没有更好的方法在 python 中处理共享内存时间序列(除了 multiprocessing.basemanager)?
非常感谢!
【问题讨论】:
-
我建议创建一个元组列表,并创建一个结构化数组一次,stackoverflow.com/q/48751127/901925
-
您知道每个
vstack都会创建一个新数组吗? -
我明白了。您对如何更有效地追加有更好的想法吗?
标签: python pandas numpy multiprocessing time-series