1

我正在使用 a pandas.HDFStore,但我找不到我想做的事情的解释,即使用select带有值过滤器的方法。

这是我想要实现的目标:我的table商店中有一个,其中的列是看起来像整数的字符串,我希望能够过滤文档中所写的值:

store.select('dfq',where="A>0 or C>0")

我的列名称如下:

In[28]: hs.select('/Data', stop=3).columns
Out[28]: 
Index(['2008', '2010', '2012', [...])

所以,我只是尝试了这个:

In[29]: t = hs.select('/Data', stop=30, columns=['2008'], where='2008>0')

但我得到了以下异常:

Traceback (most recent call last):
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3066, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-29-53380a428bf5>", line 1, in <module>
    t = hs.select('/Data', stop=30, columns=['2008'], where='2008>0')
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 669, in select
    return it.get_result()
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 1352, in get_result
    results = self.func(self.start, self.stop, where)
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 662, in func
    columns=columns, **kwargs)
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 3990, in read
    if not self.read_axes(where=where, **kwargs):
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 3196, in read_axes
    self.selection = Selection(self, where=where, **kwargs)
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 4545, in __init__
    self.condition, self.filter = self.terms.evaluate()
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 580, in evaluate
    self.condition = self.terms.prune(ConditionBinOp)
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 118, in prune
    res = pr(left.value, right.value)
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 113, in pr
    encoding=self.encoding).evaluate()
  File "C:\Users\bourgault_j\AppData\Local\Anaconda3\lib\site-packages\pandas\computation\pytables.py", line 317, in evaluate
    raise ValueError("query term is not valid [%s]" % self)
ValueError: query term is not valid [[Condition : [None]]]

我也尝试了以下表达式,但结果是一样的:

hs.select('/Data', stop=30, columns=['2008'], where='"2008">0')

在这种情况下,有人给我小费吗?

请注意,我更愿意保留这些列名称,因为它们在我的代码的其他部分用作键。

附加说明:我已经可以做这样很酷的事情了:

hs.select('/Data', columns=['2008'], where='index>"2015-10-19 14:49:00.01"')
4

0 回答 0