python - 使用 odo 转换 pandas hdfstore 时维护数据列

标签 python pandas hdfstore blaze

我正在使用 blaze 项目中的 odo 来按照此问题中的建议合并多个 pandas hdfstore 表:Concatenate two big pandas.HDFStore HDF5 files

这些商店具有相同的列和不重叠的设计标记以及几百万行。单个文件可能适合内存,但整个组合文件可能无法适合。

有没有办法可以保留创建 hdfstore 时使用的设置?我丢失了数据列和压缩设置。

我尝试了 odo(part, Whole, datacolumns=['col1','col2']) 但没有运气。

或者,任何有关替代方法的建议将不胜感激。我当然可以手动执行此操作,但随后我必须管理 block 大小以免耗尽内存。

最佳答案

odo 不支持压缩 和/或data_columns ATM 的传播。两者都很容易添加,我创建了一个问题 here

您可以通过以下方式在 pandas 中执行此操作:

In [1]: df1 = DataFrame({'A' : np.arange(5), 'B' : np.random.randn(5)})

In [2]: df2 = DataFrame({'A' : np.arange(5)+10, 'B' : np.random.randn(5)})

In [3]: df1.to_hdf('test1.h5','df',mode='w',format='table',data_columns=['A'])

In [4]: df2.to_hdf('test2.h5','df',mode='w',format='table',data_columns=['A'])

迭代输入文件。 block 读/写到最终存储。请注意,您还必须在此处指定 data_columns

In [7]: for f in ['test1.h5','test2.h5']:
   ...:     for df in pd.read_hdf(f,'df',chunksize=2):
   ...:         df.to_hdf('test3.h5','df',format='table',data_columns=['A'])
   ...:         

In [8]: with pd.HDFStore('test3.h5') as store:
    print store
   ...:     
<class 'pandas.io.pytables.HDFStore'>
File path: test3.h5
/df            frame_table  (typ->appendable,nrows->1,ncols->2,indexers->[index],dc->[A])

关于python - 使用 odo 转换 pandas hdfstore 时维护数据列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30470352/

相关文章:

python - 打开作为记录存储在 Django 数据库中的文本文件

python - 计算 Pandas 中一列字符串中的单词

python - 计算 pandas 中的唯一值对

python - Pandas HDFStore : Saving and Retrieving a Series with Hierarchical Period Index

python - Pandas HDFStore 从嵌套列中选择

python - Dataframe Slice 不删除索引值

python - 使平面适合 3D 中的一组点 : scipy. optimize.minimize vs scipy.linalg.lstsq

python - 非常 simplejson 解码

python - 如果左右 df 的键不同,pandas merge 会做奇怪的工作

python - HDF5 min_itemsize 错误 : ValueError: Trying to store a string with len [##] in [y] column but this column has a limit of [##]!