Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何查询通过Pandas Dataframe保存的PyTables frame_表?_Python_Pandas_Hdf5_Pytables_H5py - Fatal编程技术网

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如果你能提供一个样本和所需的数据集,答案可能会更简洁