无法将 pandas 数据帧保存到 HDF 文件
Can't save pandas dataframe to HDF file
我一直在尝试将 pandas 数据帧保存到 HDF5 文件中。我尝试了各种不同的措辞,例如。 df.to_hdf
等,但无济于事。我 运行 在 python 虚拟环境中看到 here。即使不使用 VE,它也有同样的错误。以下脚本出现以下错误:
''' This script reads in a pickles dictionary converts it to panda
dataframe and then saves it to an hdf file. The arguments are the
file names of the pickle files.
'''
import numpy as np
import pandas as pd
import pickle
import sys
# read in filename arguments
for fn in sys.argv[1:]:
print 'converting file %s to hdf format...' % fn
fl = open(fn, 'r')
data = pickle.load(fl)
fl.close()
frame = pd.DataFrame(data)
fnn = fn.split('.')[0]+'.h5'
store = pd.HDFStore(fnn)
store.put([fn.split('.')[0]], frame)
store.close()
frame = 0
data = 0
错误是:
$ ./p_to_hdf.py LUT_*.p
converting file LUT_0.p to hdf format...
Traceback (most recent call last):
File "./p_to_hdf.py", line 22, in <module>
store = pd.HDFStore(fnn)
File "/usr/lib/python2.7/site-packages/pandas/io/pytables.py", line 270, in __init__
raise Exception('HDFStore requires PyTables')
Exception: HDFStore requires PyTables
pip list
显示已安装 pandas 和表以及最新版本。
pandas (0.16.2)
tables (3.2.0)
解决方案与代码无关,而是如何在 python 中 source
虚拟环境。正确的方法是使用 . venv/bin/activate
而不是 source ~/venv/bin/activate
。现在 which python
显示 python 安装在 ~/venv/bin/python
下,代码运行正确。
我一直在尝试将 pandas 数据帧保存到 HDF5 文件中。我尝试了各种不同的措辞,例如。 df.to_hdf
等,但无济于事。我 运行 在 python 虚拟环境中看到 here。即使不使用 VE,它也有同样的错误。以下脚本出现以下错误:
''' This script reads in a pickles dictionary converts it to panda
dataframe and then saves it to an hdf file. The arguments are the
file names of the pickle files.
'''
import numpy as np
import pandas as pd
import pickle
import sys
# read in filename arguments
for fn in sys.argv[1:]:
print 'converting file %s to hdf format...' % fn
fl = open(fn, 'r')
data = pickle.load(fl)
fl.close()
frame = pd.DataFrame(data)
fnn = fn.split('.')[0]+'.h5'
store = pd.HDFStore(fnn)
store.put([fn.split('.')[0]], frame)
store.close()
frame = 0
data = 0
错误是:
$ ./p_to_hdf.py LUT_*.p
converting file LUT_0.p to hdf format...
Traceback (most recent call last):
File "./p_to_hdf.py", line 22, in <module>
store = pd.HDFStore(fnn)
File "/usr/lib/python2.7/site-packages/pandas/io/pytables.py", line 270, in __init__
raise Exception('HDFStore requires PyTables')
Exception: HDFStore requires PyTables
pip list
显示已安装 pandas 和表以及最新版本。
pandas (0.16.2)
tables (3.2.0)
解决方案与代码无关,而是如何在 python 中 source
虚拟环境。正确的方法是使用 . venv/bin/activate
而不是 source ~/venv/bin/activate
。现在 which python
显示 python 安装在 ~/venv/bin/python
下,代码运行正确。