2014-02-14 70 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