源码

首页 » 归档 » 源码 » python – Pandas无法读取用h5py创建的hdf5文件

python – Pandas无法读取用h5py创建的hdf5文件


当我尝试读取用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

File path: test.h5
Empty

用h5py读取刚刚创建的文件没有麻烦:

h5_back = h5py.File('test.h5', 'r')
h5_back['/zeros']

使用这些版本:

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'

提前谢谢了,
马沙

(1)

本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/python-pandaswufaduquyongh5pychuangjiandehdf5wenjian.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:9月 26, 2019 at 03:21 下午

热评文章