我有一个存储在 HDF5 文件中的大型 Pandas 数据框。Dataframe 是具有 Datetime 和 PatientID 的多索引。
store = pd.HDFStore('prepro_mon.h5',mode='r')
print(store.get_storer('raw_import').levels)
Out: ['Datetime', 'PatientID']
但是按患者 ID 过滤 Select 语句不起作用。
store.select('raw_import', where='PatientID = 88000')
我收到这个错误
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4660, in generate
return Expr(where, queryables=q, encoding=self.table.encoding)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 524, in __init__
self.terms = self.parse()
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 742, in parse
return self._visitor.visit(self.expr)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 312, in visit
return visitor(node, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 318, in visit_Module
return self.visit(expr, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 312, in visit
return visitor(node, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 321, in visit_Expr
return self.visit(node.value, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 312, in visit
return visitor(node, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 643, in visit_Compare
return self.visit(binop)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 312, in visit
return visitor(node, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 415, in visit_BinOp
op, op_class, left, right = self._possibly_transform_eq_ne(node)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 353, in _possibly_transform_eq_ne
left = self.visit(node.left, side='left')
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 312, in visit
return visitor(node, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\expr.py", line 429, in visit_Name
return self.term_type(node.id, self.env, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 41, in __init__
super(Term, self).__init__(name, env, side=side, encoding=encoding)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\ops.py", line 58, in __init__
self._value = self._resolve_name()
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 47, in _resolve_name
raise NameError('name {0!r} is not defined'.format(self.name))
NameError: name 'PatientID' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "H:\OxygenationIndex\dataloaderOIFeatures.py", line 51, in <module>
store.select('raw_import', where='PatientID = 88000')
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 724, in select
return it.get_result()
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 1423, in get_result
results = self.func(self.start, self.stop, where)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 717, in func
columns=columns, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4266, in read
df = super(AppendableMultiFrameTable, self).read(**kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4086, in read
if not self.read_axes(where=where, **kwargs):
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 3287, in read_axes
self.selection = Selection(self, where=where, **kwargs)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4647, in __init__
self.terms = self.generate(where)
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4672, in generate
.format(where, ','.join(q.keys()))
ValueError: The passed where expression: PatientID = 88000
contains an invalid variable reference
all of the variable refrences must be a reference to
an axis (e.g. 'index' or 'columns'), or a data_column
The currently defined references are: SvO2,AWPMean,peep_s,SpO2,fiO2_m,TempCentral,tv_m,fiO2_s,HF,RR_s,TempPeri,etCO2,tv_s,peep_m,peakP_m,RR_m,columns,StayMinutes,VentMode,plateauP,index
任何帮助深表感谢。我不确定这是否可能是一个错误,因为我一直在阅读应该可以按索引查询。