【发布时间】:2016-02-11 23:52:42
【问题描述】:
当我尝试读取使用 h5py 创建的 HDF5 格式文件时出现 pandas 错误。我想知道我是不是做错了什么?
import h5py
import numpy as np
import pandas as pd
h5_file = h5py.File('test.h5', 'w')
h5_file.create_dataset('zeros', data=np.zeros(shape=(3, 5)), dtype='f')
h5_file.close()
pd_file = pd.read_hdf('test.h5', 'zeros')
给出一个错误: TypeError:如果对象不存在也没有传递值,则无法创建存储器
我尝试将密钥集指定为“/zeros”(就像我在读取文件时使用 h5py 一样)但没有成功。
如果我使用 pandas.HDFStore 读取它,我会得到一个空存储:
store = pd.HDFStore('test.h5')
>>> store
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
Empty
使用 h5py 读取刚刚创建的文件没有问题:
h5_back = h5py.File('test.h5', 'r')
h5_back['/zeros']
<HDF5 dataset "zeros": shape (3, 5), type "<f4">
使用这些版本:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
pd.__version__
'0.16.2'
h5py.__version__
'2.5.0'
提前非常感谢, 玛莎
【问题讨论】: