21

以下を使用してファイルを作成しました。

store = pd.HDFStore('/home/.../data.h5')

以下を使用していくつかのテーブルを保存しました。

store['firstSet'] = df1
store.close()

Python を終了し、新しい環境で再開しました。

このファイルを再度開くにはどうすればよいですか?

私が行くと:

store = pd.HDFStore('/home/.../data.h5')

次のエラーが表示されます。

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/misc/apps/linux/python-2.6.1/lib/python2.6/site-packages/pandas-0.10.0-py2.6-linux-x86_64.egg/pandas/io/pytables.py", line 207, in __init__
    self.open(mode=mode, warn=False)
  File "/misc/apps/linux/python-2.6.1/lib/python2.6/site-packages/pandas-0.10.0-py2.6-linux-x86_64.egg/pandas/io/pytables.py", line 302, in open
    self.handle = _tables().openFile(self.path, self.mode)
  File "/apps/linux/python-2.6.1/lib/python2.6/site-packages/tables/file.py", line 230, in openFile
    return File(filename, mode, title, rootUEP, filters, **kwargs)
  File "/apps/linux/python-2.6.1/lib/python2.6/site-packages/tables/file.py", line 495, in __init__
    self._g_new(filename, mode, **params)
  File "hdf5Extension.pyx", line 317, in tables.hdf5Extension.File._g_new (tables/hdf5Extension.c:3039)
tables.exceptions.HDF5ExtError: HDF5 error back trace

  File "H5F.c", line 1582, in H5Fopen
    unable to open file
  File "H5F.c", line 1373, in H5F_open
    unable to read superblock
  File "H5Fsuper.c", line 334, in H5F_super_read
    unable to find file signature
  File "H5Fsuper.c", line 155, in H5F_locate_signature
    unable to find a valid file signature

End of HDF5 error back trace

Unable to open/create file '/home/.../data.h5'

ここで何が間違っていますか?ありがとうございました。

4

3 に答える 3

10

私の手には、次のアプローチが最適です。

df = pd.DataFrame(...)

"write"
with pd.HDFStore('test.h5',  mode='w') as store:
    store.append('df', df, data_columns= df.columns, format='table')

"read"
with pd.HDFStore('test.h5',  mode='r') as newstore:
    df_restored = newstore.select('df')
于 2015-07-08T18:17:55.530 に答える
5

代わりに次のことを試すことができます。

store = pd.io.pytables.HDFStore('/home/.../data.h5')
df1 = store['firstSet']

または read メソッドを直接使用します。

df1 = pd.read_hdf('/home/.../data.h5', 'firstSet')

いずれにせよ、pandas 0.12.0 以降が必要です...

于 2014-07-07T10:10:13.860 に答える
2

私は同じ問題を抱えていましたが、最終的にpytablesモジュールをインストールすることで修正しました(使用していたpandasモジュールの隣):

condaはpytablesをインストールします

これにより、numexpr-2.4.3 と pytables-3.2.0 が得られました

その後、うまくいきました。Python 2.7.9でパンダ0.16.2を使用しています

于 2015-06-30T07:13:07.297 に答える