当列名为整数时,根据值从HDFStore表中选择数据

时间:2016-01-12 12:51:43

标签: python select pandas hdfstore

我正在使用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"')

0 个答案:

没有答案