【问题标题】:How can I store an array or list of Strings in a PyTable?如何在 PyTable 中存储数组或字符串列表?
【发布时间】:2015-04-17 13:25:04
【问题描述】:

例如,我有以下表格描述。在 SpectrumL 中,我想存储一个我还不知道确切大小的(频谱图)。同样,我想存储一些标签(将是字符串),它们的大小会因记录而异。但是,当我尝试为此执行构建语句时,出现以下错误:

TypeError: Passing an incorrect value to a table column. Expected a Col (or subclass) instance and got: "StringAtom(itemsize=20, shape=(), dflt='')". Please make use of the Col(), or descendant, constructor to properly initialize columns. 

我正在执行的语句是:

h5file = tables.open_file("foo.h5", mode = "w", title = "Datastore")
group = h5file.create_group("/", 'metadata', 'General MetaData')
table =  h5file.create_table(group, 'footer', hdf5Pull.BuildTable, "information")

表语句类为:

   class BuildTable(IsDescription):
        artist_id = StringCol(100)
        tags = StringAtom(itemsize = 20)
        spectrumL = Float64Atom((5000, 1))
        spectrumR = Float64Atom((5000, 1))
        frequency = Float64Atom((5000, 1))

有人能帮忙看看这个吗?我在理解文档时遇到了一些麻烦。谢谢!

【问题讨论】:

    标签: python database hdf5 pytables


    【解决方案1】:

    错误消息包含所有信息。您必须使用Col 或子类,但您提供的是Atoms

    table 语句必须是这样的:

    class BuildTable(IsDescription):
            artist_id = StringCol(100)
            tags = StringCol(itemsize = 20)
            spectrumL = Float64Col(shape=(5000, 1))
            spectrumR = Float64Col(shape=(5000, 1))
            frequency = Float64Col(shape=(5000, 1))
    

    如果您想在单个单元格中存储多个值,则必须依赖多维单元格(请参阅here)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      相关资源
      最近更新 更多