python - HDFStore高效使用指南
问题描述
在我的数据处理应用程序中,我大约 80% 的处理时间都花在了函数pandas.HDFStore.put
上。尽管围绕类似问题存在各种 SO 问题,但我还没有找到任何关于如何以HDFStore
最有效方式使用的明确指南。
我有哪些选择来减少写作时间?
我的数据仅包含 float64 列和一些备用 int 列,它可能包含重复的索引和/或列名,并且它是先验未排序的。它将是数十年收集的数据(秒-分钟分辨率),因此该解决方案应该是可扩展的。
我的基本用例如下:
# 1. Store creation
store = pd.HDFStore(pro['hdf_path'], complevel=7,
complib='blosc', fletcher32=True)
# 2. Iterative addition of new data
store.put('/table/T1', data, format='table', data_columns=True,
append=True, index=False)
# 3. Basic queries of certain columns (I only need 'index' in 'where')
store.select('/table/T1', columns=['A', 'B', ...],
where='index>="{}" & index<{sign}"{}"'.format(_t1, _t2))
# 4. Retrieving a tree with all tables and all column
# names in that table (without loading it)
for path, groups, leaves in store.walk():
...
for lv in sorted(leaves):
_item_path = '/'.join([path, lv])
columns = store.get_node('{}/table'.format(_item_path)).description._v_names
具体来说,我会对如何更改以下参数以优化写入时间感兴趣:
- 'complib', 'complevel' 在商店创建中
- 使索引更有效(也许
create_table_index
只在最后调用?) store.put
/的参数store.append
- 我读了一些关于指数水平的东西,比如
('medium', 6)
,这会有影响吗? - 我可以通过减少例如毫秒来将索引从日期时间(然后存储为 Int64)减少到更有效的东西吗?
(阅读与其说是一个问题,不如说store.select
是where=...
相当有效的。)
感谢您的帮助,非常感谢!
解决方案
推荐阅读
- javascript - Browserify 窗口函数未定义
- react-native - BottomTabNavigator 未出现在屏幕底部
- android - 直接从 fresco 的管道中获取中心裁剪的图像
- pytorch - pytorch customdataset notimplemented错误
- javascript - Angular,使用基于父组件的短组件选择器
- python - Tensorflow 子类模型中的后续迭代返回无类型“缓存”张量
- java - 为返回所有数据但不包括某些列的本机查询重用实体的方法
- arrays - 比较两个数组并删除不在另一个数组中的数据
- sympy - sympyfourier_series 中是否有错误?
- python - 扫描关键字的 url 列表