首页 > 解决方案 > 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

具体来说,我会对如何更改以下参数以优化写入时间感兴趣:

(阅读与其说是一个问题,不如说store.selectwhere=...相当有效的。)

感谢您的帮助,非常感谢!

标签: pythonpandashdfstore

解决方案


推荐阅读