Python 如何查询通过Pandas Dataframe保存的PyTables frame_表?
我有以下数据帧:Python 如何查询通过Pandas Dataframe保存的PyTables frame_表?,python,pandas,hdf5,pytables,h5py,Python,Pandas,Hdf5,Pytables,H5py,我有以下数据帧: import pandas as pd df = pd.read_table('fname.dat') 因此,我创建/打开一个现有的HDFStore文件: store = pd.HDFStore('store.h5') 为了索引列的子集,我只需使用 store.append('key_name', df, data_columns=['colA','colB','colZ']) 显然,HDFStore.append()以table格式保存每个默认数据帧。但是,它看起来实际
import pandas as pd
df = pd.read_table('fname.dat')
因此,我创建/打开一个现有的HDFStore文件:
store = pd.HDFStore('store.h5')
为了索引列的子集,我只需使用
store.append('key_name', df, data_columns=['colA','colB','colZ'])
显然,HDFStore.append()
以table
格式保存每个默认数据帧。但是,它看起来实际上是一个“frame_table”对象:
store
输出
/key_name frame_table (typ->appendable,nrows->3254334,ncols->14,indexers->[index],dc->[colA, colB, colZ])
如何有效地索引此对象
通常,查询是
result = [row for row in table.where('colA==22 & colB==45')]
但是对于
frame\u表
对象会这样做吗 frame\u table
-表示它是以table
格式保存的数据帧
当使用data\u columns=['colA'、'colB'、'colZ']
参数时,您已经“索引了”['colA'、'colB'、'colZ']
列
因此,现在您可以按如下方式查询HDFStore:
store = pd.HDFStore('store.h5')
varA = 100
varZ = 'string_value'
df = store.select('key_name', where='colA >= varA & colZ == varZ')
或者,您可以使用pd.read\u hdf(…)
而不是store.select(…)
PS如果你能提供一个样本和所需的数据集,答案可能会更简洁