python 桌面应用 h5,在Python中打开.h5文件

I am trying to read a h5 file in Python.

The file can be found in this link and it is called 'vstoxx_data_31032014.h5'. The code I am trying to run is from the book Python for Finance, by Yves Hilpisch and goes like this:

import pandas as pd

h5 = pd.HDFStore('path.../vstoxx_data_31032014.h5', 'r')

futures_data = h5['futures_data'] # VSTOXX futures data

options_data = h5['options_data'] # VSTOXX call option data

h5.close()

I am getting the following error:

h5 = pd.HDFStore('path.../vstoxx_data_31032014.h5', 'r')

Traceback (most recent call last):

File "", line 1, in

h5 = pd.HDFStore('path.../vstoxx_data_31032014.h5', 'r')

File "C:\Users\Laura\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 466, in __init__

self.open(mode=mode, **kwargs)

File "C:\Users\Laura\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 637, in open

raise IOError(str(e))

OSError: HDF5 error back trace

File "C:\aroot\work\hdf5-1.8.15-patch1\src\H5F.c", line 604, in H5Fopen

unable to open file

File "C:\aroot\work\hdf5-1.8.15-patch1\src\H5Fint.c", line 1085, in H5F_open

unable to read superblock

File "C:\aroot\work\hdf5-1.8.15-patch1\src\H5Fsuper.c", line 277, in H5F_super_read

file signature not found

End of HDF5 error back trace

Unable to open/create file 'path.../vstoxx_data_31032014.h5'

where I have substituted my working directory for 'path.../' for the purpose of this question.

Does anyone know where this error might be coming from?

解决方案

In order to open a HDF5 file with the h5py module you can use h5py.File(filename). The documentation can be found here.

import h5py

filename = "vstoxx_data_31032014.h5"

h5 = h5py.File(filename,'r')

futures_data = h5['futures_data'] # VSTOXX futures data

options_data = h5['options_data'] # VSTOXX call option data

h5.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值