【问题标题】:Peek the number of rows in an hdf5 file in pandas在 pandas 中查看 hdf5 文件中的行数
【发布时间】:2014-12-15 10:41:09
【问题描述】:

我想知道是否有一种方法可以轻松、快速且无需加载整个文件,获取使用 pandas 和 pandas 创建的 hdf5 文件中的行数?

提前谢谢你!

【问题讨论】:

  • 您是否在您想要的列上尝试了一个简单的pandas.read_hdf() 后跟len()?这种事情肯定适用于h5py,但我不能 100% 确定 PyTables 的阅读行为。

标签: python-2.7 pandas hdf5 hdfstore


【解决方案1】:
In [1]: DataFrame(np.random.randn(10,10)).to_hdf('test.h5','df',mode='w',format='table')

In [3]: store = pd.HDFStore('test.h5')

In [4]: store
Out[4]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df            frame_table  (typ->appendable,nrows->10,ncols->10,indexers->[index])

In [5]: store.get_storer('df').nrows
Out[5]: 10

【讨论】:

  • 我注意到对于固定格式的表格,上述操作给出了None。一个简单的解决方法是store.get_storer('df').shape[0]
  • 我在 REPL 中可视化 store 时没有得到 /df ... 信息,但在执行 store.get_storer('df') 时得到了它。 (我的数据框存储为table,键为df
猜你喜欢
  • 2018-10-11
  • 2014-07-14
  • 2012-08-01
  • 2019-05-20
  • 2015-08-11
  • 2016-01-28
  • 1970-01-01
  • 2014-09-19
  • 1970-01-01
相关资源
最近更新 更多