【问题标题】:Selecting Columns by a string - Pytables按字符串选择列 - Pytables
【发布时间】:2014-09-09 22:39:18
【问题描述】:

我知道我们可以使用table.cols.somecolumn 访问列,但我需要对表的 10-15 列应用相同的操作。所以我想要一个迭代的解决方案。我将列的名称作为列表中的字符串:['col1','col2','col3']

所以我正在寻找类似的东西:

for col in columnlist:
    thiscol = table.cols[col]
    #apply whatever operation

【问题讨论】:

    标签: python pytables


    【解决方案1】:

    试试这个:

    columnlist = ['col1','col2','col3']
    for col in columnlist:
        thiscol = getattr(table.cols, col)
    

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      相关资源
      最近更新 更多