2014-02-14 26 views
9

我遇到了一个HDFStore问题分组,后来证明这个分组基于包含'&'字符的字符串来选择行。这应该说明问题熊猫和HDF5,查询一个表,包含'&'字符的字符串

>>> from pandas import HDFStore, DataFrame 
>>> df = DataFrame({'a': ['a', 'a', 'c', 'b', 'test & test', 'c' , 'b', 'e'], 
        'b': [1, 2, 3, 4, 5, 6, 7, 8]}) 
>>> store = HDFStore('test.h5') 
>>> store.append('test', df, format='table', data_columns=True) 
>>> df[df.a == 'test & test'] 
 
    a    b 
4 test & test 5 
>>> store.select('test', 'a="test & test"') 
 
Int64Index([], dtype='int64') Empty DataFrame 

现在我如果我错过从documentation的东西,或者如果这是一个错误疑惑。

+3

错误....在这里看到:https://github.com/pydata/pandas/issues/6351;我不觉得很难解决,我们有一个预解析器,基本上可以替代某些表达式;需要让它不会在引号内做到 – Jeff

+0

明白了,谢谢! –

+1

这只是合并在......所以请尝试与主! – Jeff

回答

-2

在我看来,h5py是一个比熊猫更健壮的HDF5文件python模块。 http://www.h5py.org/

+2

问题是关于如何使用熊猫。这个答案与手头的问题无关。 – tharen

1

正如评论,这是现在固定的(因为熊猫0.14):

In [11]: df[df.a == 'test & test'] 
Out[11]: 
      a b 
4 test & test 5 

In [12]: store.select('test', 'a="test & test"') 
Out[12]: 
      a b 
4 test & test 5