【问题标题】:Pandas and HDF5, querying a table, string containing '&' characterPandas 和 HDF5,查询表,字符串包含 '&' 字符
【发布时间】:2014-03-13 05:26:18
【问题描述】:

我在使用 HDFStore 进行分组时遇到了问题,结果扩展到基于包含“&”字符的字符串来选择行。这应该能说明问题

>>> 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']
一个 4 测试 & 测试 5
>>> store.select('test', 'a="test & test"')
Int64Index([], dtype='int64') 空数据帧

现在我想知道我是否遗漏了 documentation 中的某些内容,或者这是一个错误。

【问题讨论】:

  • 错误....见这里:github.com/pydata/pandas/issues/6351;我不认为很难修复,我们有一个预解析器,它基本上可以替换某些表达式;需要让它不要在引号内这样做
  • 刚刚被合并到......所以请大师试试!

标签: python pandas hdf5


【解决方案1】:

正如评论,现在已修复(自 pandas 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

【讨论】:

    【解决方案2】:

    在我看来,h5py 是一个比 pandas 更强大的 HDF5 文件 python 模块。 http://www.h5py.org/

    【讨论】:

    • 问题是关于如何使用 Pandas。这个答案与手头的问题无关。
    猜你喜欢
    • 2011-05-14
    • 2011-03-30
    • 2011-02-05
    • 2019-05-25
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    相关资源
    最近更新 更多