【问题标题】:mystery when storing a dataframe containing strings in HDF with pandas使用 pandas 在 HDF 中存储包含字符串的数据帧时的谜团
【发布时间】:2012-10-16 20:42:19
【问题描述】:

这里有一些关于万圣节的熊猫和 HDF 令人毛骨悚然的东西:

df = pandas.DataFrame([['a','b'] for i in range(1,1000)])
store = pandas.HDFStore('test.h5')
store['x'] = df
store.close()

然后

ls -l test.h5
-rw-r--r-- 1 arthur arthur 1072080 Oct 26 10:50 test.h5

110 万?有点陡峭,但为什么不呢。这就是事情变得真正令人毛骨悚然的地方

store = pandas.HDFStore('test.h5') #open it again
store['x'] = df #do the same thing as before!
store.close()

然后

ls -l test.h5
-rw-r--r-- 1 arthur arthur 2122768 Oct 26 10:52 test.h5

您现在已进入暮光区。不用说,运行后store是没有区别的,但是每次迭代都让文件有点胖。

似乎只有在涉及字符串时才会发生。 在我提交错误报告之前,我想知道我是否在这里遗漏了什么......

【问题讨论】:

标签: python pandas hdf5


【解决方案1】:

是的:“HDF5 不是数据库”。人们经常使用 ptrepack(PyTables 的一部分)来“重新打包”HDF5 文件而不会出现任何死字节。

【讨论】:

    【解决方案2】:

    看来可能是这个原因:http://www.hdfgroup.org/hdf5-quest.html#del

    这是 HDF5 的一大难题,wtf。

    【讨论】:

      猜你喜欢
      • 2018-02-10
      • 1970-01-01
      • 2011-11-30
      • 2016-12-20
      • 2017-09-12
      • 1970-01-01
      • 2016-11-26
      • 2015-12-27
      • 1970-01-01
      相关资源
      最近更新 更多